Introduction To C Programming
Introduction To C Programming
C programming
#include <stdio.h>
#include <stdlib.h>
int main()
printf("Hello world!\n");
return 0;
}
Source Binary
Compiler
Code Code
.
Operator Action
– Subtraction
+ Addition
* Multiplication
/ Division
% Modulus
–– Decrement
++ Increment
Operator Action
== Equal
!= Not equal
Logical Operators Bitwise Operators
|| OR | OR
%s String of text
%u Unsigned decimal integer (int)
%% (percent character)
1. If()…..else Statement
if (condition 1 is met)
{
do Task A
}
else if (condition 2 is met)
{
do Task B
}
else if (condition 3 is met)
{
do Task C
}
else
{
do Task D
}
If()….else Demo
2. The ternary operator (?)
case secondCase:
do B;
break;
default:
do C;
break;
}
Switch Statement Demo
There are 3 types of loop in C programming language, namely:
1. for loop
2. while loop
3. do…while loop
1. for( ) loop
The for statement executes a block of code repeatedly until the test condition
is no longer valid.
}
for( ) loop Demo
while (condition test) { //Statements to be executed repeatedly // Increment (++) or Decrement (--) Operation }
2. while( ) loop
A while statement repeatedly executes instructions inside the loop while a certain
The do-while statement is similar to the while statement with one main
do{
//Statements
while(condition test);
do…while loop Demo
The general form of a function is :
Logic;
Executable Statement 1;
……
}
There are two methods to pass the data into the function in C language :
1. Pass by value
In pass by value method, the value of the actual parameters is copied into the formal
parameters. In other words, we can say that the value of the variable is used in the
2. Pass by referent
In call by reference, the address of the variable is passed into the function call as the actual
parameter.
Pass by value example
Pass by referent example
Arrays a kind of data structure that can store a fixed-size sequential collection of
char letter[30];
Single dimension array code example
The general form for declaring a two-dimension array is :
Example :