C Syllabus 2
C Syllabus 2
● Installation
■ IDE (Integrated Development Environment) --> VS Code
■ Compiler --> Mingw - gcc
■ Extensions --> C C++, Code runner
● Syntax
● Variable Declaration
■ A name given to a memory location
■ Declared by writing type variable_name;
■ Initialized and declared by type variable_name = value;
◆ Pointer
◆ Structure
◆ Union
● Operators
■ Arithmetic Operators
◆ +, -, *, /, % --> modulus
■ Relational / Conditional / Comparison Operators
◆ ==, >=, <=, <, >, !=
■ Logical Operators
◆ && --> AND, || --> OR, ! --> NOT
■ Assignment Operators
◆ =, +=, -=, *=, /=
● Keyword or Functions
■ Printf(); --> use to print the character / result / output
■ Scanf(); --> use to read character / value assign
■ Sizeof(); --> use to check size of data types
● Escape Sequences --> \a, \b, \n, \t, \v, \\, \’, \”
● Operator Precedence in C
■ 1st --> !
■ 2nd --> *, /, %
■ 3rd --> +, -
■ 4th --> <, >, <=, >=
■ 5th --> ==, !=
■ 6th --> &&
■ 7th --> ||
■ 8th --> =
● If Else
■ If
■ Else
■ Else if
■ Nested If
■ Exercise:
◆ C program to convert temperature from Fahrenheit to Celsius and Celsius to
Fahrenheit (F = (C x 1.8)+ 32) (C = (F - 32) x 0.556)
◆ C program to check whether a character is an alphabet or not
◆ C program to check whether the triangle is valid or not if angles are given
● Ternary Operator
● Switch Case
■ Rules:
◆ Switch expression must be int or char.
■ Exercise:
◆ Write a C program to print day of week name using switch case.
◆ Write a C program print total number of days in a month using switch case.
◆ Write a C program to check whether an alphabet is vowel or consonant using switch
case.
◆ Write a C program to find the maximum between two numbers using a switch case.
◆ Write a C program to check whether a number is even or odd using a switch case.
◆ Write a C program to check whether a number is positive, negative or zero using a
switch case.
◆ Write a C program to create Simple Calculator using a switch case.
● Loops
■ Types:
◆ While Loop
◆ Do While Loop
◆ For Loops
■ Advantages:
◆ Code reuse-ability.
◆ Saves time
◆ Traversing Arrays
● Break;
● Continue;
● Functions
■ Used to divide a large c program into smaller pieces.
■ A function can be called multiple times to provide reusability to the C program.
■ Also called procedure or subroutine
● Pointers --> Data type which holds the address of other data types
● Strings
■ C language does not support strings as a data type.
■ We express strings using an array of characters terminated by a null character ('\0').
■ String: array of characters terminated by NULL character / null terminated character array
■ Gets(); --> to take string from user
■ Puts(); --> to print string as output
■ We can create a character array using the following ways:
◆ Char name[] = "deepak";
● Typedef
● Unions --> Union is a collection of similar / non-similar elements but we can use only one at a
time
■ Dynamic Memory Allocation is a way in which the size of a data structure can be changed
during the runtime.
■ Methods