Gate-2017 C - Programming Solved Questions
Void printxy(int x, int y) {
Int *ptr;
X=0;
Ptr=&x; // ptr->(x=0)
Y=*ptr;// y=0
*ptr=1;//x=1
Printf(“%d%d”,x,y);
}
The output of invoking printxy(1,1) is:Ans. 1,0
#include
Int main(){
Int m=10;
Int n,n1;
n=++m; // n=11
n1=m++; //n1=12
n--; //n=10
--n1; //n1=11
n-=n1; // n=n-n1i.e n=10-11=-1
printf(“%d”,n);
return 0;
}
The output of program is:
Ans. -1
3.Consider the following function implemented in C:
#include#include Int main() { Char *c=”GATECSIT2017”; Char *p=c; Printf(“”,(int)strln(c+2[p]-6[p]-1));// Return 0; }
The output of program is:
Ans. 2
4. Consider the following of a c program .assume that swap(&x,&y) exchange the content of x and y:
Int main() {
Int array[]={3,5,1,4,6,2};
Int done=0;
Int I;
While(done==0) {
Done=1;
For(i=0;i<=4;i++) {
If(array[i]<array[i+1){
Swap(&array[i],&array[i+1]);
done=0;
}
}
For(i=5;i>=1;i--) {
If(array[i]>array[i-1){
Swap(&array[i],&array[i-1]);
done=0;
}
}
}
Printf(“%d”,array[3]);
}
The output of program is:
Ans. 3

No comments