0% found this document useful (0 votes)
10 views

Operator - Classroom - Examples

The document contains 13 code snippets that demonstrate various C programming concepts like data types, operators, control flow, functions, and input/output. Specifically, it shows the sizeof operator, integer and float division, assignment operators, logical operators, precedence of operators, conditional (if/else) statements, formatting output, and user input.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views

Operator - Classroom - Examples

The document contains 13 code snippets that demonstrate various C programming concepts like data types, operators, control flow, functions, and input/output. Specifically, it shows the sizeof operator, integer and float division, assignment operators, logical operators, precedence of operators, conditional (if/else) statements, formatting output, and user input.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

1.

int main() {

int n=0;

char c=’c’;

float f=34.5;

n=sizeof(int);

printf(“%d\n”,n);

printf(“%lu\n”,sizeof c);

printf(“%lu\n”, sizeof ‘c’);

printf(“%lu\n”, sizeof 34.5);

printf(“%lu\n”, sizeof(float));

printf(“%lu\n”,sizeof(“float”));

printf(“%lu\n”,sizeof(“12.34”));

printf(“%lu\n”,sizeof(“c”));

2. int main()

int i1=5, i2=2;

int i3;

float f;

i3 = i1/i2;

f = i1/i2;

printf(“i3=%d f=%f\n”,i3,f);

i3=i1/(float)i2;

f = i1 / (float)i2;

printf(“i3=%d f=%f\n”,i3,f);

3. int main()

int x=10,y=20,z=30;

printf(“%d %d %d\n”,x,y,z);

x=y=z=40;

printf(“%d %d %d\n”,x,y,z);

}
4. int main(){

int x=10,y=20,z=30,result=-1;

result=z>y>x;

printf(“result=%d\n”,result);

5. int main(){

int i=20.5;

float f=20.4;

int result;

result= i==f;

result=i==(int)f;

result= (float)i==f;

result=i<f;

result=i<(int)f;

6. int main(){

int i=-1;

int result;

result= sizeof(i) > i ;

printf(“result=%d\n”,result);

7. int main(){

int a=10,b=20;

printf(“a=%d b=%d\n”,a,b);

//b=a*b/a=b;

b=a*b/(a=b);

//b=(a*b)/(a=b);

//b=((a*b)/(a=b));

printf(“a=%d b=%d\n”,a,b);

8. int main(){ float var=23.4;

printf(“%d\n”, var==23.4);

var=23.25;
printf(“%d\n”, var==23.25); }

9. int main(){

int a=10,b=11;

printf(“%d\n”, ++a > b--);

printf(“a=%d b=%d\n”,a,b);

a=10;b=11;

printf(“%d\n”,a++ < --b);

10. int main(){ int a=5,b=0,c=-3,d=-1;

printf(“%d %d %d %d\n”,a,b,c,d);

d=a&&b;

printf(“%d %d %d %d\n”,a,b,c,d);

d=b||c;

printf(“%d %d %d %d\n”,a,b,c,d);

d= !a || !c;

printf(“%d %d %d %d\n”,a,b,c,d);}

11. int main() {

int a=5,b=0,c=-3,d=-1;

printf(“%d %d %d %d\n”,a,b,c,d);

d= ++a || ++b || ++c;

printf(“%d %d %d %d\n”,a,b,c,d);

a=5;b=0;c=-3;d=-1;

d= b++ && c++ && a++;

printf(“%d %d %d %d\n”,a,b,c,d);

a=5;b=0;c=-3;d=-1;

d= ++b && ++c && ++a;

printf(“%d %d %d %d\n”,a,b,c,d);}

12.

int main(){
int a,b,c;

int result;

printf(“enter 3 integers:”);

scanf(“%d%d%d”, &a,&b,&c);

result= (a<0) &&(b<0)&&(c<0);

result=(a>b)&&(b>c);}

13. int main(){ int result;

char ch;

printf(“enter a char:”);

scanf(“%c”,&ch);

result=(ch>=65)&&(ch<=90);

result=(((ch>=’A’)&&(ch<=’Z’)) || ((ch>=’a’) && (ch<=’z’)))}

You might also like