Consider the following C code. Assume that unsigned long int type length is 64 bits. unsigned long int fun(unsigned long int n){ unsigned long int i, j = 0, sum = 0; for (i = n; i > 1; i = i/2) j++; for ( ; j > 1; j = j/2) sum++; return(sum); } The value returned when we call fun with the input 240 is
Category: GATE C
C Program GATE 2018 -7
Consider the following C program: #include<stdio.h> void fun1(char *s1, char *s2){ char *tmp; tmp = s1; s1 = s2; s2 = tmp; } void fun2(char **s1, char **s2){ char *tmp; tmp = *s1; *s1 = *s2; *s2 = tmp; } int main(){ char *str1 = “Hi”, *str2 = “Bye”; fun1(str1, str2); printf(“%s %s “, str1, str2); fun2(&str1, &str2); printf(“%s %s”, str1, str2); return 0; } The output of the program above is
C Program GATE 2018 -5
Consider the following C program. #include <stdio.h> struct Ournode{ char x,y,z; }; int main(){ struct Ournode p = {‘1’, ‘0’, ‘a’+2}; struct Ournode *q = &p; printf (“%c, %c”, *((char*)q+1), *((char*)q+2)); return 0; } The output of this program is?
C Program GATE 2019 -4
C Program : GATE 2019 Consider the following C program: #include <stdio.h> int main(){ float sum = 0.0, j = 1.0, i = 2.0; while (i/j > 0.0625){ j = j + j; sum = sum + i/j; printf(“%fn”, sum); } return 0; } The number of times the variable sum will be printed, when the above program is executed, is _________________.
C Program GATE 2019-3
C Program : GATE 2019 Consider the following C program: #include <stdio.h> int r(){ static int num=7; return num–; } int main(){ for (r();r();r()) printf(“%d”,r()); return 0; } Which one of the following values will be displayed on execution of the programs?
C Program GATE 2019-2
C Program : GATE 2019 Consider the following C function. void convert(int n){ if(n<0) printf(“%d”,n); else { convert(n/2); printf(“%d”,n%2); } } Which one of the following will happen when the function convert is called with any positive integer n as argument?
C Program GATE 2019-1
C Program : GATE 2019 Consider the following C program #include <stdio.h> int main(){ int arr[]={1,2,3,4,5,6,7,8,9,0,1,2,5}, *ip=arr+4; printf(“%dn”, ip[1]); return 0; } The number that will be displayed on execution of the program is ___________ .
C Program GATE 2019-6
C Program : GATE 2019 Consider the following C program: #include <stdio.h> int jumble(int x, int y){ x=2*x+y; return x; } int main(){ int x=2, y=5; y=jumble(y,x); x=jumble(y,x); printf(“%d n”, x); return 0; } The value printed by the program is ________.