Notes On C
Notes On C
1. Syntax of C Program
Example
#include <stdio.h>
int main()
printf("Hello World!");
return 0;
float 4 bytes Stores fractional numbers, containing one or more decimals. Sufficient for storing 6-7
decimal digits
double 8 bytes Stores fractional numbers, containing one or more decimals. Sufficient for storing 15
decimal digits
3. Operators in C
C divides the operators into the following groups:
Arithmetic operators
Relational operators
Logical operators
Assignment operators
Increment and decrement operators
Ternary or conditional operators
Arithmetic Operators
+, -, *, /(div), % (mod)
5/2=2 5%2=1
Relational Operators
<, >, <=, >=,!=,==
4<1 false 4>2 true 4<=5 true 5<=5 true 5==5 true
5!=5 false
Logical Operators
Logical operators are used to determine the logic between variables or values:
&& Logical and Returns true if both statements are true x < 5 && x < 10
! Logical not Reverse the result, returns false if the result is true !(x < 5
&& x < 10)
Assignment Operators
=, +=, -=, *=,/=, %=
= x=5 x=5
+= x += 3 x=x+3
-= x -= 3 x=x-3
*= x *= 3 x=x*3
/= x /= 3 x=x/3
%= x %= 3 x=x%3
|= x |= 3 x=x|3
Max=(5>3)?5 : 3;
Switch statements
If-else statements:
The if-else statement is C's most fundamental decision-making statement. It enables us
to run one block of code if a given condition is met and another if it is not. An if-else
statement in C has the following basic syntax:
if (condition)
else
Switch statements:
Syntax:
switch (expression)
{
case value1:
break;
case value2:
break;
...
default: