Professional Documents
Culture Documents
CS 101 Homework 02
CS 101 Homework 02
Q. 1. Execute and write the outputs of the following programs and with valid
justifications:
(a)
#include<stdio.h>
int main()
int x =120;
printf("%d %d %d",x,x++,++x);
printf("\n\n");
x =120;
printf("%d %d %d",x++,++x,x);
return 0;
OUTPUT:
122 121 122
(b)
#include<stdio.h>
int main(){
int x =120;
printf("%d %d %d",x,x++,++x);
printf("\n\n");
x=120;
printf("%d %d %d",x,++x,x++);
//compiler goes due to operator printed
// x as it is 122 122
printf("\n\n");
x=120;
printf("%d %d %d",++x,x++,x);
printf("\n\n");
x=120;
printf("%d %d %d",x++,++x,x);
// x as it is 120 122
printf("\n\n");
x =120;
printf("%d %d",x,x++);
// x as it is 121 121
// 121 120
printf("\n\n");
x =120;
printf("%d %d",x,++x);
// x as it is 121 121
// 121 121
printf("\n\n");
x =120;
printf("%d %d",x++,++x);
// 121 122
printf("\n\n");
return 0; }
OUTPUT :
122 121 122
122 122 120
121 120
121 121
121 122
(c)
#include<stdio.h>
int main(){
int i=5,j;
//compiler never add three numbers, it first add two then next one
// due to operator i= 6 7
// ++i + ++i
// due to operator i= 8
// 14 + ++i
// value at that place 14 8
printf("%d %d",i,j);
return 0;
OUTPUT :
8 22
(d)
#include<stdio.h>
int main(){
int i =5,j;
//due to operator 6 7 8
printf("%d %d",i,j);
return 0;
OUTPUT :
8 24
(e)
#include<stdio.h>
int main(){
int a,b,c,d,i=2;
a= ++i + ++i;
//due to operator 3 4
// a= ++i + ++i
// a=8
printf("a=%d\n",a);
i=2;
b= i++ + i++;
//due to operator 3 4
// b= i++ + i++
// b= 5
printf("b=%d\n",b);
i=2;
c= ++i + i++;
//due to operator 3 4
// c= ++i + i++
// c= 7
printf("c=%d\n",c);
i=2;
d= i++ + ++i;
//due to operator 3 4
// d= i++ + ++i
// d= 6
printf("d=%d\n",d);
return 0;
OUTPUT :
a=8
b=5
c=7
d=6
(f)
#include<stdio.h>
int main(){
int a,b,c,d,i=2;
a= ++i + ++i;
//due to operator 3 4
// a= ++i + ++i
// a=8
printf("a=%d\n",a);
i=2;
b= i++ + i++;
//due to operator 3 4
// b= i++ + i++
// b= 5
printf("b=%d\n",b);
i=2;
c= ++i + i++;
//due to operator 3 4
// c= ++i + i++
// c= 7
printf("c=%d\n",c);
i=2;
d= i++ + ++i;
//due to operator 3 4
// d= i++ + ++i
// d= 6
printf("d=%d\n",d);
return 0; }
OUTPUT :
a=8
b=5
c=7
d=6
THANK YOU