What is Language?
NEED Translator……
How Can We Communicate With Machine?
So, What is C?
We Need For C..
• Code Editor
• Translator
Why Separate ,Lets Integrate…
• Source Code Editor
• Compiler/Interpreter
• Debugger
• Build Automation Tools
Lets Install IDE
Lets Start Coding …
#include<stdio.h>
void main()
{
printf("YOUR TEXT");
}
#include<stdio.h>
/*multiple line
until end by */
void main()
{
//single line comment
// write anything
printf("YOUR TEXT");
}
Rules for Keywords in C:
1. Predefined and Reserved:
- Keywords have predefined meanings in C and cannot be used for anything other than their intended
purpose.
2. Case-Sensitive:
- Keywords are case-sensitive, meaning `int` is a keyword, but `Int` or `INT` is not.
3. Cannot Be Used as Identifiers:
- Keywords cannot be used as variable names, function names, or any other identifiers.
4. Always Written in Lowercase:
- All keywords in C are written in lowercase (e.g., `int`, `return`, `while`).
Examples of C keywords include: `int`, `return`, `if`, `else`, `while`, `for`, `void`, `char`, etc.
#include<stdio.h>
int var;
void main()
{
var=10;
printf("var: %d",var);
}
#include<stdio.h>
int var;
void main()
{
int var;
var=10;
printf("var: %d",var);
}
INPUT from USER
If else with logical and Relational
Operator
#include<stdio.h>
void main()
{
int a,b,c,d,e; //a=1 ,b=1,c=0,d=1,e=0;
a=1;
b=1;
c=0;
d=1;
e=0;
if(a && b && (!c) && d && (!e) )
{
printf("condition fill up");
}
else
{
printf("Not fill up.");
}
}
Switch Case
#include<stdio.h>
void main()
{
int x; //1-4;
x=0;
switch(x)
{
case 1:
printf("Temperature L1");
break;
case 2:
printf("Temperature L2");
break;
case 3:
printf("Temperature L3");
break;
case 4:
printf("Temperature L4");
break;
default:
printf("Nothing");
}
}
#include<stdio.h>
void main()
{
int x;
x=10;
while(1)
{
printf("siam , %d\n",x);
x--;
if(x<5)
break;
}
}
#include<stdio.h>
void main()
{
int x;
x=0;
while(x)
{
printf("siam , %d\n",x);
x--;
}
do
{
printf("siam , %d\n",x);
// x--;
}while(x)
}
#include<stdio.h>
void main()
{
int i;
i=10;
printf("i: %d\n",i); //10
printf("i: %d\n",i++); //10
printf("i: %d\n",i); //11
printf("i: %d\n",++i); //12
}
Array
• Declaration
• Array to Array Copy
• 2D ARRAY
#include<stdio.h>
void main()
{
float mark[]={100,50,30,60,40};
for(int i=0;i<50;i++)
{
printf("Student %d, %f\n",i,mark[i]);
}
}
#include<stdio.h>
void main()
{
float mark[]={100,50,30,60,40};
float m[5];
for(int i=0;i<5;i++)
{
m[i]=mark[i];
}
for(int i=0;i<5;i++)
{
printf("Student %d, %f\n",i,m[i]);
}
}
String
• Declaration
• Length
• Copy
• Single charater
#include<stdio.h>
#include<string.h>
void main()
{
char a[]="siam";
char b[20];
strcpy(b,a);
printf("name: %s",b);
}
char a[]="siam";
int z;
z=strlen(a);
printf("l: %d",z);
Function
• Sum, square
• Array to function
• String to Function
• Top bottom
Pointer
#include<stdio.h>
#include<string.h>
void main()
{
int x=10;
int *y;
y=&x;
printf("%x\n",&x); // x variable er memory
location(adress)
printf("%x\n",y); // x er memory location/
adress y er modhe save ache
printf("%d",*y); // y er value ja hbe tar
memory location(adress) a kon value save ache
ta show korbe
}
Structure
• struct
• typedef
• to Function
#include<stdio.h>
struct person
{
int age;
float salary;
}; // person name ekta user define datatype define korechi
void main()
{
int a,b,c; // data type> int variable>a,b,c
struct person siam, saum; // data type> person variable>siam,saum
siam.age=100; // structure er kono variable er element gula ke acces korte (.) use kora hoi
siam.salary=10;
printf("%d",siam.age);
}
#include<stdio.h>
typedef struct
{
int age;
float salary;
}person;
//tyepdef use kore user define data type aro clear kore define kora jai
void main()
{
int a,b,c;
person siam, saum; //ekhane person er age ar struct use korte hoi nai
siam.age=100;
siam.salary=10;
printf("%d",siam.age);
}
enumeration
• enum
• typedef
• to Function
#include<stdio.h>
typedef enum
{
sun,mon,tue,wed,thurs,fri
}days;
/* struct er motoi same vabe user define data
type define kora jai,
-element gular sequence onujai or value set hoi
*/
void main()
{
days day;
day=fri;
if(day==fri)
printf("Today is Chuti");
}
Macros
• #define
• #ifdef
• #if
• #inline function
#include<stdio.h>
#define pi 3.14 // kono word ba leter er modhe
constant save rakhar moto
void main()
{
// jodi pi define kora thake tahole ei
#ifdef er modher instruction gula kaj korbe
#ifdef pi
printf("%f",pi);
#endif // pi
}
Task….