Professional Documents
Culture Documents
scanf("%d",&nHrs);
scanf("%f",&profit);
scanf("%c",&c);
}
Data Types
#include<stdio.h> //standard i\o header file
void main()
{
//declaration
int i;
//initilization
i=1;
printf("i=%d \n",i);
double d=3.5;
i=d;
printf("i=%d \n",i);//will print integer (casting)
printf("d=%lf \n",d);
d=4; //casting to float
printf("d=%lf \n",d);
//print formatted
printf("%s",f);
//////assignment
const int h=10;
d=PI;// from # define
}
Operators Shorthand
Operators
void main()
{
int x=2;
int y=3;
printf("div= %d\n",x/y);//zero
printf("div= %d\n",y/x);//one
printf("rem= %d\n",x%y);//2
printf("5/2(lf)= %lf \n",5/2);
printf("5/2(d)= %d \n",5/2);
printf("5.0/2(d)= %lf\n",5.0/2);//make one of num double
printf("x/y(d)= %d\n",x/y);//2/3
x+=2;//x=x+2
x*=2+y;//x=x*(2+b)
}
Operators
void main()
{
int i=0;
i+=1;//1
i++;//2 post inc
printf("i=%d \n",i);
++i;//3 //pre inc same like post
printf("i=%d \n",i);
printf("i++=%d \n",i++);//print then inc (3)
printf("++i=%d \n",++i);//inc then print 5
}
Exercise
• Post and pre increment
• https://webrewrite.com/c-objective-questions-answers-operators-set-1/