Introduction To C Programming
Introduction To C Programming
programming
C programming
Structure of C programming
#include <stdio.h>
#include <stdlib.h>
Source code
int main()
printf("Hello world!\n");
return 0;
}
Compiler
Source
Compiler Binary Code
Code
+ Addition
* Multiplication
/ Division
% Modulus
–– Decrement
++ Increment
Arithmetic Operators Demo
Relational Operators
Operator Action
== Equal
!= Not equal
Logical and Bitwise Operators
|| OR | OR
Data_type varible1;
int number;
Data_type variable2;
Example
char character;
Data_type variable3;
: :
float weight;
: :
: :
Data_type variable n;
Conversion Character
Conversion Character Displays Argument (Variable’s Contents) As
%c Single character
%d Signed decimal integer (int)
%s String of text
%u Unsigned decimal integer (int)
%% (percent character)
Control Statement
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
}
Control Statement
If()….else Demo
Control Statement
2. The ternary operator (?)
case secondCase:
do B;
break;
default:
do C;
break;
}
Control Statement
Switch Statement Demo
Loops
Type of loop in C
1. for loop
2. while loop
3. do…while loop
Loops
1. for( ) loop
The for statement executes a block of code repeatedly until the test condition
is no longer valid.
}
Loops
for( ) loop Demo
while (condition test) { //Statements to be executed repeatedly // Increment (++) or Decrement (--) Operation }
Loops
2. while( ) loop
A while statement repeatedly executes instructions inside the loop while a certain
do{
//Statements
while(condition test);
Loops
do…while loop Demo
Functions
The general form of a function is :
Logic;
Executable Statement 1;
……
}
Functions
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.
Functions
Pass by value example
Functions
Pass by referent example
Arrays
Arrays a kind of data structure that can store a fixed-size sequential collection of
char letter[30];
Arrays
Single dimension array code example
2 dimensional array
The general form for declaring a two-dimension array is :
Example :
Thank you !