1. What is the output of the program given below
#include<stdio.h> main() { char i=0; for(;i>=0;i++) ; printf("%d\n",i); }
---2. What is the output of the following program #include<stdio.h> main() { int i=0; fork();
printf("%d",i++); fork(); printf("%d",i++); fork(); wait(); }
---3. What is the memory allocated by the following definition ? int (*x)[10]; 20 bytes,array of pointers
---4. What is the memory allocated by the following definition ? int (*x)(); 2 bytes,pointer to a function
---5. In the following program segment
#include<stdio.h> main() { int a=2; int b=9; int c=1; while(b) { if(odd(b)) c=c*a; a=a*a; b=b/2; } printf("%d\n",c); } How many times is c=c*a calculated?
---6. In the program segment in question 5 what is the value of a at the end of the while loop?
---7. What is the output for the program given below
typedef enum grade{GOOD,BAD,WORST,BAD}; cant define twice(BAD)
main() { BAD g1; g1=1; printf("%d",g1); } ans: error
---8. Give the output for the following program.
#define STYLE1 char main() { typedef char STYLE2; STYLE1 x; STYLE2 y; clrscr(); x=255; y=255;
printf("%d %d\n",x,y);} ans: -1 -1 bcoz it is char
---9. Give the output for the following program segment.
#if def TRUE int I=0; #endif
main() { int j=0; printf("%d %d\n",i,j); } ans 0 0
---10. In the following program
#include<stdio.h>main(){ char *pDestn,*pSource="I Love India"; pDestn=malloc(strlen(pSource)); strcpy(pDestn,pSource); printf("%s",pDestn); free(pDestn); }(a)Free() fails (b)Strcpy() fails (c)prints I love
India (d)error ans c
---11. What is the output for the following program
#include<stdio.h>
main(){ char a[5][5],flag; a[0][0]='A'; flag=((a==*a)&&(*a==a[0]));
printf("%d\n",flag);} ans: 1
---12. main(){ int i; i=(2,3); printf("%d",i); }
a)2 b)3 c)Compiler error d)Syntax error. ans : 3
---13 main(){ char str[]="GESL"; printf("%d %d",sizeof(str),strlen(str)); } a)5,5 b)4,4 c)5,4 d)4,5 ans: 5, 4 ---14. main(){ int i ; for(i=0;i++;i<100) printf("hello world\n"); }
a)100 times b)0 times c)Infinite loop d)None of the above. ans: 0 times. ---15. main(){ for(i=1;i++;i<100) printf("hello world\n"); }
a)100 b)0 times c)Infinite loop d)None of the above. ans: infinite loop ---16 main(){ char c; scanf("%s",c); } a)Compiler dependent b)unpredictable c)Compiler error d) scans the
i/p. ans: Compiler dependent.
---17. main(){int k=5; for(++k<5 && k++/5 || ++k<8); printf("%d\n",k);}a)5 b)6 c)7 d)8 ans: 7 ---18. main(){ int *ptr1,*ptr2; ptr1=(int *)malloc(sizeof(int)); ptr2=func(20,10,ptr1); printf("%d %d\n",*ptr1,*ptr2); } int *func(int a, int b, int *c) { int x=a+b; *c=a-b; return(&x); }
a)Bug in the code. b)No Bugs prints correctly c)Error d) None of the above. Ans: Bug in the code. ---19. int main() {int i = 10, j ; if ( ( j = ~i ) < i ) printf ( "True" ) ; else printf ( "False" ) ; } a) True b) False
c) Compiler Dependent d) None of the above. ans : False
---20. How many bytes are required to create a 3*3 matrix using double pointer ans: 12 ---21. take int=4,float=8,char=1;main() {FILE *fp;printf("%d\n",sizeof(fp) ); } a)2 b)4 c)Compiler
dependent d)Error Ans:4
---22. main(){ int a=10,20; a^=b^=a^=b; printf("%d\n %d\n",a,b);} a)a=20,b=10 b)a=10,b=20 c)Syntax
error d)Unpredictable Ans : a=20 b=10
---23. main() {int i=10; switch(i) { case 10: printf("Hello "); { case 1 : printf("World "); } case 5:
printf("Hello World "); } } a) Hello b) Hello c) Hello World Hello World d) Syntax Error. Ans : Hello World Hello World
---24. main() {char str1[]="Hello"; char str2[]="Hello"; if ( str1==str2 ) printf("True\n"); else
printf("False\n"); }a)True b)False c)Error d) Unpredictable. Ans: False. ---25. main(){ # include <stdio.h> int i = 10 ; printf("%d\n", i/2 ); }
a)10 b)5 c)error d) warning. ans : b
---26. #include <stdio.h> # pragma pack(2)
struct SIZE { int i; char ch ; double db ; } ;
main () { printf ( "%d\n",sizeof(struct SIZE) ); } a)12 b)14 c)16 d)8
---27)main() { int arr[]={ 1,2,3,4 }; int *ptr ;;;; ptr++ = arr; printf("%d,%d",ptr[2],arr[2]);return 0; } what is the output :a> compile time error :multiple termination statements for pointer
b> lvalue required for ptr c> prints 3 3 d> printd 4 3 ans b: lvalue required for ptr; ---28 main() { char s[10]; scanf ("%s",s); printf(s); } what is the output if input is abcd :
a> prints abcd b> compiler error c> prints abcd and 6 junk characters d> printd s
---29 main() { char c = 255; printf ("%d",c); return 0; } what is the output
a> illegal character assignment b> prints –1 c> prints 2 d> prints 255 ans b: prints -1.
---30 main() { int i; for (i=7;i<=0;i--) printf ("hello\n"); } what is the output a> prints hello 7 times b> prints hello 8 times c> prints hello once d> prints nothing ans b: prints nothing. ---31main() { printf( printf ("world") ); } a> prints world b> prints printf ("world") c> prints nothing d>
compiler error ans d: compiler error.
---32. What is the output of the following code ?int main( ) { for( ; ;); printf("Hello\n"); return 0; } a. give compilation error b. prints Hello infinite times c. Runs in an infinite loop without printing
anything. d. prints Hello once. Ans: c
---33. Output of the code?
FUNC (int *p) { p = (int *)malloc(100); printf("p:%x",p); } int main( ) { int *ptr; FUNC(ptr); printf("Ptr:%x",ptr); return 0; }
a. Both printf statements prints same values. b. Both print different values. c. Gives compile time error.
d. Gives run time error. Ans: b
---34. Output of the code?
int main(){ char a[] = "world"; printf("%d %d\n",strlen(a),sizeof(a)); return 0; }
a. 5,5 b. 6,5 c. 5,6 d. 6,6 Ans: c
---. 35 What is the output generated? main(){ char *s = "Hello"; printf("%s",1(s)); }
a. Hello b. ello c. e d. none of these. Error
---36. Interpret the given declaration
char ( * ( f ( ) ) [ ] ) ( ) a. f is a pointer to function returning char b. f is a pointer to an array of function returning a char c. Invalid declaration d. f is a function returning pointer to array[] of
pointer to function returning char. Ans : d
---37 .what is the o/p ? void main(){ char *mess[]={"Have","a","nice","day","Bye"); printf("%d \t
%d",sizeof(mess),sizeof(mess[1])); }
a. 16 4 b. 5 4 c. 20 4 d. Error ans: c
---38.what is the o/p of the following programe?
void main() { int i,count=0; char *p1="abcdefghij"; char *p2="alcmenfoip"; for(i=0;i<=strlen(p1);i++) { if(*p1++ == *p2++) count+=5; else count-=3; } printf("count=%d\n",count); }
a. 15 b. 6 c. 12 d. compiler error ans:9 ans: b
---39.what does main return on successful execution? a. 1 b. 0 c. –1 d.Nonzero ans:b
---40 main(int argc,char *argv[]) { printf((argc > 1 ? "%c" : "%c",*++argv); } If the i/p string is "GESL
Bangalore". a. G b. E c. B d. GESL ans: c
---41. How do u declare a pointer to an array of pointers to int? a. int *a[5]; b. int **a[5]; c. int *(*a)[5];
u cannot declare ans: c
---42) main(){ int a; char *p; a = sizeof(int) * p; printf("%d\n",a);} a)compile error b)run time error
c)4 d)compiler dependent ans:a
---43)#define SIZE sizeof(int)
main(){ int i=-1; if( i < SIZE ) printf("True\n"); else printf("False\n"); }
a) True b) False c) can't predict d) None of these ans:b
---44) int (*fun())[]
a) function returning a pointer to an array b) function returning an array of pointers c) pointer to a
funtion which takes array as asrument d) Compiler error ans: a
---45) main() { int a=8,d; int *p; p=&a; d=a/(*p); print("%d\n",d); }
a) 1 b) 0 c) compiler error d) run time error ans: a
---46) main(){ char *a="Hello"; *a++ = 'h'; printf("%s\n",a); }a) hello b) ello c) runtime error d)
compiler error ans:b
---47) main(){ char p[]="Hello"; p[0]='h'; printf("%s\n", p); }a) hello b) Hello c) compiler error d) run
time error ans:a
---48)#define mysizeof(a) (&a+1) - &a
main(){float d; printf("%d\n", mysizeof(d) ); }
note: assume sizeof float is 8 bytes a) 8 b) 4 c) 1 d) compiler error ans:c ---49) main() { int *p=10; printf("%d\n",*p); }
a) 10 b) run time error c) compiler error d) 5 ans:b
---50)main(){int i=-1; i<<=2; printf("%d\n",i); }
a) –1 b) –2 c) –4 d) 0 ans:c
---51) main(){ int i= 0xffffffff; printf("%d\n",i); } note: size of int is 4 bytes
a) –1 b) 65635 c) 100 d) error ans:a
---52)#include<stdio.h> main() { scanf("%d"); printf(); } which of the following is correct?
a)compilation error b)Run time error c)No output d)depends on the compiler ans : a ---53)#include<stdio.h> #define islower(c) ('a'<=(c) && (c)<='z')
#define toupper(c) (islower(c)?(c)-('a'-'A'):(c))
main() { char *p="i am fine"; while(*p) printf("%c",toupper(*p++)); }
a)bcd b)AFE c)aFe d)BCd ans : b
---54) #include<stdio.h> main() { 200; printf("tricky problem"); }
a)warning message b)compilation error c)run time error d)none of these ans : a ---55)which is the null statement? a) ; b) {} c) '\0';d)all of these ans : a ---56)what is the correct prototype of printf function ? a)printf(char *p,...); b)printf(const *char *p,...);
c)printf(const char *p,...); d)printf(const *char p,...); ans : c
---57)main(){int *p ; p=(int *)malloc(-10); }
a) allocates 0 bytes b) allocates memory, if available c) compilation error d) Runtime error Ans) b ---58). main(){ for( printf("a") ; printf("b") ; printf("c") ) ; }
a) abc b) abc abc abc ...(infinite times) c) a bc bc bc ....(infinite times) d) Error Ans) c ---59) main() { int i= 10 * fun() ; printf("%d",i); } fun(){return 10 ; }
a) 0 b) 10 c) 100 d) Error Ans) c
---60). int i= 10 * fun(); main(){printf("%d",i); } fun() {return 10 ;}
a) 0 b) 10 c) 100 d) Error Ans) d ---61). Assume size of int to be 2 bytes : main(){int i = 100 ; printf("%d ", sizeof(i++));printf("%d ",i) ;}
a) 2 100 b) 2 101 c) 100 101 d) 101 100 Ans) a
bcoz sizeof operator does effect the i++;
---62) main(){ int A=1,B=2;if(A==B < printf("Hello ")) printf("world\n"); else printf("Bangalore\n"); } What is the o/p? a> world b> Hello bangalore c> bangalore d> Hello world. ans > d> Hello world. ---63)main() { int i; for(i=0; i< 10; i++){ int j=10; j++;printf("j= %d\n", j);}} what is o/p ?
a> 10 to 19 b> error j undeclared c> 10 times 11 d> 10 – 18 ans> c> 10 times 11. ---64) union test{ int a; union test *p; }; main(){ union test q; printf(" a= %d\n ", q.a); } what is o/p?
a> 0 b> syntax error c> garbage value d>run time error ans > c ---65)register int a,b; main(){ for(a=0 ; a<5 ; a++) b++; } a> 5 b> 4 c> 0 d> error ans > d ---66) # define dprint(expr) printf(" expr= %d \n ", expr)
main(){ int i=10,j=2;dprint(i / j) ;} a> 5 b > expr= 5 c> i / j= 5 d> error. ans > b. ---67) What is the Output of the Program ?main(){ int a = 1; #define p a printf("%d %d ",a++,p++) ;} a) 1, 0
b) 2, 0 c) 1 2 d) none of the above (2,1) Ans (d)
---68)#include<stdio.h> main(){ #include<stdio.h> int a = 90 ; printf("%d",a) ; }
a) 90 b) compilation error c) linker error d) runtime error Ans (a)
---69) What is the Output of the Program ?main(){main() ;}a) compilation error b) runtime error c) executes
until the stack overflows(1) d) none of the above Ans (c)
---70) What is the Output of the Program ?
#define max "hello" main(){ printf(max) ;}
a. compilation error b. Preprocessing error c. runtime error d. hello Ans (d)
---71) What is the Output of the Program ?#define max main() main() { max ; printf("hello wolrd\n ") ; } a. compilation error b. Preprocessing error c. runtime error d .executes until the stack overflows ans:d ---72) What is the Output of the Program ?
typedef int *p ; main() { int a = 90 ; p p1 ; p1 = &a ; printf("%d",*p1) ; }
a. 90 b. compilation error c. runtime error d. none of the above Ans (a)
---73) What is the Output of the Program ?
main() { int i = 1 ; printf(i ?"one" : "zero") ; } a. one b. zero c.error d. both and b Ans (a) ---74) What is the Output of the Program ?
main(){ int i = 1 ;printf("%d",i ? 1 : 0) ;}a. 1 b. 0 c. error d. none of the above ans(a) ---75). What is the Output of the Program ?
main() {int a = 90 , b = 100 ;a++ ;a = (a ^ b) ^ (a = b ); b = a^b^a ;--a ;printf("%d %d",a++,b++) ; }
a. 90 100 b. 100 90 c. 101 91 d. 91 101 Ans (a)
---76) What is the Output of the Program ?
main(){ int a = 10 , b = 100 ;swap(&a , &b) ; printf("%d %d",a,b) ;} swap(int *a , int *b){*a = *a + *b ; *b = *a - *b ;*a = *a - *b ; swap1(&a , &b) ;} swap1(int **a , int **b){**a = **a + **b ;**b = **a - **b ;**a = **a - **b ;}
a. 100 10 b. 10 100 (1) c lvalue is required in fun main d. error !! Ans (b) ---77)What is the Output of the Program ?
main(){ void *ptr ;int a = 10 ;ptr = &a ;printf("%d",*ptr) ;}
1. error 2. 10 3. 20 4. none Ans (1)
---78) What is the Output of the Program ?
main(){ void *ptr ;int a = 90 ;char *ptr1 = "hello" ;ptr = a ;ptr = ptr1 ;}
a. executes w/o any error b. compilation error c. runtime error d.none Ans (a)
79) What is the Output of the Program ?
main(){ char *p = "helloo" ;char *p1 = "strcat" ;while((*(p++) = *(p1++)) != '\0'){;}}
---80). What is the Output of the Program ?
int g = 10 ;main(){int a = 10 ;printf("%d",a) ;}int g ; a. 10 b. 11 c.error d. none Ans (a) ---81). What is the Output of the Program ?
main(){ int a = 1 ;int b = 0 ;a = a++ + --b * a++ ;printf("%d",a) ;}
a. error b. none c. 1 d .2 Ans (d)
---82) What is the Output of the Program ?struct s{ int si;union u{float uf;char uc;};}; main(){
printf("%d",sizeof(struct s));} a. 8 b. 3 c. 6 @ d. 7
---83 What is the Output of the Program ?
struct st{int a;char b;}main(){} a. struct st is return type of main@ b. main is a variable of struct st.c.
Compilation error d. Run time error Ans (A)
---84) What is the Output of the Program ?
typedef struct info{int i;char b;} node;
main(){ struct info node1;node1.i=55; printf("%d",node1.i);}
a. 55 b. Not possible to use struct info c.Compilation error d. Garbage value. Ans (A) ---85) What is the Output of the Program ?
struct a{int i;int display(){ printf("hello world\n");}};
main(){ strcut a vara; vara.display();} a. hello b. hello world c. Compile time error d. garbage
---86. What is the Output of the Program ?
struct a{ int (*ptr)();};int display(){ printf("Global Edge\n");} main(){struct a structa;structa.ptr=display;structa.ptr();}
A. Global Edge B. Address of display function C. address of structa D.Error Ans (A) ---87. What is the Output of the Program ?
typedef int *ABC; typedef ABC XYZ[10]; int main() { XYZ var;}
1. var is an array of integer pointers. 2. var is a pointer to an integer array.Options:a) only 1 is correct. b) only 2 is correct. c) both 1 and 2 are correct.d) typedef statements are in wrong order. Ans : b ---88. What is the Output of the Program ?
union tag{ int a; char x; char y;}name;(Assume Storage is Little Endian technique) int main(){name.a=258;printf("\n x = %d y = %d ",name.x,name.y);}
a) x = 1 y = 1 b) x = 2 y = 2 c) x = 1 y = 2 d) x = 2 y = 1 Ans : b ---89. Consider the Program, int main(){int a[20];int *p,*q,val;p = &a[0];q = &a[10];val = q - p;printf("p %u q %u val %d ",p,q,val);} Assume p = 1000, what is the value of q and val ?
a) q = 1020 val = 20 b) q = 1020 val = 10 c) q = 1010 val = 10d) q = 1010 val = 20 ans : b ---90. Consider the Program,
struct key{char *word[2]; int count;char c;}abc;int main(){printf("\nsize %d",sizeof(abc));}
What is the size of abc?(a) 8 (b)7(c)6(d)5 Ans : b
---91. What is the output of the following program ?
main(){ int a; fun(); printf("%d",a); a=50;} fun(){ int i; *(&i+4) = 100;} a. 50 b. Garbage value c. 100 d. Compiler error
---92. What is the output of the program ?
main(){ #define x 5 int b; b = x; printf("%d",b); } a. Compiler Error b. Runtime error c. Garbage value d. 5
---93. What is the output of the following program ?
main(){ int a; #define y 10 a=y; printf("%d",a); } a. 10 b. Compiler error c. Run-time error d. Garbage value
---94. What will be printed on the screen ?
#define s -50 main(){int s; #ifdef s printf("Hell\n");#else printf("Heaven\n"); #endif} a. Hell b. Heaven c. Compilation error d. HellHeaven
---95. Which of 'Arrays' or 'pointers' are faster ?
a. Arrays b. pointers c. Both take same time d. Can't say
---96)How many times can a comment be nested ?
A)comment_nest_limit times B)comment_limit times C)one time D)Not even Once (R)
---97)Which one MUST be correct in the following statements ? A)All Identifiers are keywords B)All Keywords are IdentifiersC)Keywords are not Identifiers D)Some keywords are Identifiers Ans (C) ---98.Select the choice which is wrong ?A)'volatile' is a reserved wordB)'volatile' is a keywordC)'volatile' is a
data type D)'volatile' is a Identifier Ans (C)
---99.Consider the following Program Ans b
main(){int i,j; i = 06; j = 09; printf ("%d %d\n",i,j);} A)6 9 B)6 11 C)06 09 D)Compilation Error ---101)What happens when we compile this program ?
# undef __FILE__ # define __FILE__ "GLOBALEDGE" main(){
printf("%s\n",__FILE__); }A)Compilation Error B)Run-Time Error C)Compiles But gives a Warning D)Compiles Normally
---102).What happens when we compile this program ?
# define LINE # define NAME "GESL" main() { printf("%d "%s\n",LINE,NAME); }
A)Compilation Error B)Compiles but Warns C)Syntax Error D)Compiles Normally
---103)int main(){ int i = 5;if(1){static int i;i++;printf("%d", i);} printf("%d", i);}
a. error b. 5,0 c. 5,1 d. 1,5 Ans (d)
---104)int main(){ int a[4] = { 23, 67, 90}; printf(" %d", a[3]);}
a. junk b. error c. 0 (ans)d. 1
---105)int main(){ int i = 1, 2; printf("%d", i); }
a. 1 b. 2 c. error d. none Ans (c)
---106)int main(){ int i; for( i=0; ; i++){i = i+2;break;printf("%d", i);}}
a. 0 b. 2 c. error d. none (ans) Ans (d)
---107)int main(){ int i; i = 1, 2; printf("%d", i);}
a. 1 (ans) b. 2 c. error d. none
---108)#include<stdio.h>int i =20;int maxlen = i;int main(){int j = i;printf("i=%d , j=%d\n", i , j);}
a) i=20 , j=20 b) i=20 , j=junk c) error d) none Ans.(c)
---109)int main(){int i =10;printf("%d", j);printf("%d",i);}int j = 20;
a) j=20 , i=10 b) j=junk , i=10 c) compile time error d) runtime error Ans (c) ---(110)int i =20;int i,j=10;main(){ int j =20; printf("i=%d , j=%d\n", i, j);}
a) redeclaration error b) i=20 , j=10 c) i=20 , j=20 (ans)d) none Ans (c)
---111)int main(){ int k=2, i =10; while(k--){printf("%d\n",disp(i)); }}
disp(int k){ static int i=0; return i=i+k;} a) 10, 10 b) 10, 20 (ans) c) 20, 10 d) none
---112)) header files usually contains a)only definitions b)only declarations (ans) c)both d)compiled code for functions
---113) int main() { int i =3; while(i--){ int i =10;printf("%d",i);}}
a) 10, 9, 8, 7, ...1 b) 10, 10, 10, 10, ... c) 10, 10, 10 (ans) d) none
---(114)char s[] = "hello\0 world"; printf("%s...%d",s,strlen(s)); What is the output?
(a) hello...5 (b) hello\0 world...12 (c) hello...12 (d) compile time error ans : (a) ---(115)printf("%%%s","hello"); What is the output?(a) %%%s (b) %%% (c) %hello (d) hello ans : (c) ---(116). What does fgetc return (a) char (b) int (c) unsigned int (d) void ans : (b)
---(117).int i = 24; printf("%xd",i); What is the output?
(a) 18 (b) 24 (c) 18d (d)compile time error ans : (a)
---(118). What is return type of freopen (a) int* (b) FILE* (c) int (d) void ans : (b) ---(119).struct node{int i;} ; main(){ struct node n1;printf("%d",n1.i);}o/p of the program:
a. 0 b. Garbage value c. error. 4.warning Ans: b ---(120) struct node_tag {int i;struct node_tag *pt;} ;main(){printf("%d",size(node_tag));}o/p of the program:
a). 4 b). 6 c).Garbage value d).error Ans:d
---(121)typedef struct node_tag {int i=0;int j;} node;main(){node n1;printf("%d",n1.i);}o/p of the program:
1. 0 2. warning 3.Garbage value 4.error Ans: d
---(122) struct {int i;}node ;main(){printf("%d",node.i);}o/p of the program:
(a). 0 (b). Garbage value (c). error. (d). warning Ans: (a)
---(123).struct node_tag {int a;struct node_tag *pt;} ;main(){struct node_tag n1;n1.pt=&n1; n1.pt->a=5; printf("%d",n1.a);}o/p of the program:
(a). error (b). warning (c). 5 (d).Garbage value Ans: (c)
---(124) int n;scanf("%d",n); what is the output?a)read 1 integer value b)compile time error c)runtime
error d)reads 0 Ans (c)
---125)strchr(s,c) what this will do?
a)return pointer to first 'c' in 's' or NULL if not present b)return pointerto last 'c' in 's' or NULL if not present c)concatenate c to s in the beginning d)concatenate c to s at the end Ans :a ---(126) When calloc() is called memory is initialised to a)Garbage b)NULL c)0 d)-1 Ans (c) ---(127) (void *) is called (a)pointer to void (b)pointer to any data type (c)generic pointer(d)None of the
above Ans (c)
---(128)What the putchar() will return on error a)0 b)EOF c)NULL d)-1 Ans (b) ---129)what is the output of the following ? i=5; i=i++ * i++; printf("%d",i); a)30 b)49 c)25 d)27 Ans (d) ---(130) what is the output of the following ? i=5;printf("%d",i++ * i++);a)30 b)49 c)25 d)37 Ans (c) ---(131)#include<stdio.h>int main(void){putchar("0123456789ABCDEFGHIJKL" [16 & 17 ] );
return NULL;}Choice(s) : a) Error b) No Output C) Garbage d) G
---132)#include<stdio.h>int main(){char *p = "Welcome To GESL\n";*(p+10);fprintf(stderr,"%s",p);return 'c';}Choice(s) : a) prints "GESL" to stderr.b) ErrorC) Garbage d) prints "Welcome To GESL" to screen ---(133)#include<stdio.h> int main(void){ puts("hello\0world");}Choice(s) : a) Error b) hello$^@$S C) hello d) world$%^#^
---(134)#include<stdio.h> typedef char (*PFI) () ;char main(int argc,char *argv[],char *environ[])
{PFI a = main;printf("%s",a);}a)Compile Time Error b)Infinite Loop c)Prints some garbage d)Run Time error
---135) union u{int ival;float fval;char *sval;} size of u is a) 8 bytes b) 4 bytesc) compile time errord) 12 ---136)struct x{int i; int j;int k; } ;struct x *p;struct x arr[3];p =&arr[0];p++;what is p pointing to
a) pointing to i of arr[0]b) pointing to j of arr[0]c) pointing to k of arr[1]d) pointing to i of arr[1]Ans (d) ---137)struct a{int b;};struct b{int b;};int main(){struct a first;struct b second;first.b =10;second =
first;printf("%d",second.b);}a) 10 b) garbage c) compile error d) run time error Ans: c ---138) struct a{int x;float y; double z;struct a b;};a) no error b) compile errorc) run time errord) none of the
above ans : b
---139) struct a{struct b{ int a;int b;}c;int *ptr;}d;d.ptr=&d.c.a;
a) compile error b) syntax error c) Both a and c d) none of the above ans : d ---140)#include<stdio.h>int main(void){int *intPtr ;intPtr = (char*)malloc(sizeof(10));printf("\n The starting address is %d \n ",intPtr);return 0;}a) Compilation Error b) Runtime Errorc) Will give a Warning , but run
any way d) neither warning nor error ans c
---141)#include<stdio.h>int main(void){FILE *fp1,*fp2;int c;fp1 = fopen("testing","a");fp2 =
fopen("testing","w");while( (c = getchar()) != '\n'){fputc(c,fp1);}return 0;} /*a) Compilation Error b) Runtime Error c) contents of file testing are appended d) contents of file testing are overwritten
---142.#include<stdio.h>int main(void){int intNum1,intNum2,num = 1,i; printf("\nEnter first number \n"); scanf("%d",&intNum1);printf("\nEnter second number \n");scanf("%d",intNum2);for(i = 0;i<=3;i++){ num = intNum1 * intNum2 * num; }printf("\n num = %d " , num);return 0;}
a) Compilation Error b) Runtime Error c) Successful execution d) Junk Value
---143).#include<stdio.h>int main(void){char str[5];char *newstr;printf("\nEnter first string \n");
scanf("%s",&str);printf("\n The string you have entered is %s ",str);newstr = gets(str);printf("\n num = %s " , newstr);printf("\n the new string is %s ",newstr);return 0;}
a) Compilation Error b) Runtime Error c) Successful execution d) Junk Value
---144)#include<stdio.h>int main(void){FILE *fp;char *str ;char *newstr;fp = fopen("source","r");newstr = fgets(str,5,fp);printf("\n The new str is %s " ,newstr);return 0;}
a) Compilation Error b) Runtime Error c) Successful execution d) Segmentation Fault
---145).int a=1,b=0, x;x = a++ && ++b;printf("%d %d %d ",a,b,x );output ?
a) 1 1 2 b) 2 1 0 c) 2 0 2 d) 2 1 1 ans: d
---146.char *fn();main(){char *s;s = fn();printf("%s\n",s );}char *fn(){ return "Hello"; }output is ?
a) null b) garbage c) Hello d) Compilation Error ans:c
---147)int i;for( i=0; i<10-1; i+=2 ); i+= 2; printf("i = %d\n", i );output is ?
a) 12 b) 11 c) 10 d) 13 ans: a
---148 what is the output of the following program ?main(){int i; i = f();printf("%d",i );}f(){ return 1,2,3;}
a) 1 b) Compilation error c) 2 d) 3 ans:d
---149)What is the difference between ++*ip and *ip++ ?a) both increment value b) ++*ip increment value and *ip++ increment addressc) both increment addressd) ++*ip increment address and *ip++ increment
value ans: b
---150.What is the output of the following program ?
# include <stdio.h>intmain ( void ) {int x, y, z;x = 2, y = 4;z = x && y; printf("z = %d\n", z );}
1) 1 2) 0 3) None of these 4) 8 Ans = 1
---(151)What is the output of the following program ?
# include <stdio.h>int main ( void ) {int x = 48;printf("x = %s\n", x );}
1) 10 2)0 3) Run Time Error 4) Compilation Error Ans = 3
---152.What is the output of the following program ?
# include <stdio.h># define ONE 1 # define TWO 2 # define ONE TWO# define TWO ONE intmain ( void ) { printf("ONE = %d, TWO = %d\n", ONE, TWO );}
1. ONE = 1, TWO = 2 2. TWO = 1, ONE = 2 3. Compilation Error4. None of these Ans = 3 ---153 If the command line arguments for the following program are <a.out> and
<GlobalEdgeSoftwareLtd>, what is the output of the program ?
# include <stdio.h>int main( int iargu, char **argvar ) {printf("output = %s\n", *argvar[1] );} 1. GlobalEdgeSoftwareLtd 2. G 3. Compilation Error 4. Run Time Error
Ans = 4
---154What is the output of the following ?
# include <stdio.h>void fun( int, int );int main ( void ) {fun( 12, ( 13, ( 14, 15 ) ) );return 0;}
void fun( int x, int y ) {printf("x = %d,y = %d\n", x, y );}1. x = 12, y = 13 2. x = 14, y = 15 3. x =
12, y = 15 4. Syntax Error( Too Many Arguments to fun() ) Ans = 3
---155)#define min((a),(b)) ((a)<(b))?(a):(b) main(){ int i=0,a[20],*ptr; ptr=a;
while(min(ptr++,&a[9])<&a[8]) i=i+1; printf("i=%d\n",i);} Ans:5. ---156)main(){char a[10]={1,2,3,4,5,6};int x;for(x=0;x<4;x++){ b[x]=x+'a';}printf("%s",b);} Ans:abcd56 ---157)char a =0xAA ;int b ; b = (int) a ;b = b >> 4 ;printf("%x",b); What is the output of the above program segment ?
---158) struct s1 { struct { struct { int x; } s2 } s3 }y; How does one access x in the above given structure definition ?
---159 )What is the size of the array declared as double * X[5] ? Ans. 5 * sizeof ( double * )
---160void f(int y){struct s *ptr;ptr = malloc (sizeof (struct)+99*sizeof(int));}struct s{int i;float p; };
when free (ptr) is executed, what will happen?
161).enum day = { jan = 1 ,feb=4, april, may}what is the value of may?a)4 b)5 c)6 d)11e)none
---162.main{int x,j,k;j=k=6;x=2;x=j*k;printf("%d", x); ans x=36
---163) fn f(x){ if(x<=0) return; else f(x-1)+x;} ans fn(5) ....?
---164). i=20,k=0;for(j=1;j<i;j=1+4*(i/j)){k+=j<10?4:3;}printf("%d", k); ans k=4
---165. int i =10 main(){int i =20,n;for(n=0;n<=i;){int i=10 i++;}printf("%d", i); ans i=20
---166. Y=10; if( Y++>9 && Y++!=10 && Y++>10)printf("... Y);else printf(".... ) ans : 13
---167. f=(x>y)?x:ya) f points to max of x and yb) f points to min of x and yc)errord) ... ans : a
---168)if x is even, then(x%2)=0x &1 !=1x! ( some stuff is there)
a)only two are correctb) three are correctc), d) .... ans : all are correct
---169. which of the function operator cannot be over loaded?a) <= b)?: c)== d)* ans: b and d
---170) main(){int x=10,y=15;x=x++;y=++y;printf("%d %d\n",x,y);}
---171)int x;main(){ int x=0;{int x=10;x++;change_value(x);x++;Modify_value(); printf("First output: d \n",x);}x++;change_value(x);printf("Second Output : %d\n",x);Modify_value();printf("Third Output : %d\n",x);} Modify_value(){ return (x+=10);} change_value(){ return(x+=1);} ---172)main(){int x=20,y=35;x = y++ + x++; y = ++y + ++x;printf("%d %d\n",x,y);} 57,94
---173main(){char *p1="Name"; char *p2; p2=(char *)malloc(20);while(*p2++=*p1++);
printf("%s\n",p2);} name
---174 main(){ int x=5; printf("%d %d %d\n",x,x<<2,x>>2);}
---175
#define swap1(a,b) a=a+b;b=a-b;a=a-b; main() { int x=5,y=10; swap1(x,y); printf("%d %d\n",x,y); swap2(x,y); printf("%d %d\n",x,y); }
int swap2(int a,int b) { int temp; temp=a; b=a; a=temp; return; } ---176 main() {
char *ptr = "Ramco Systems"; (*ptr)++;
printf("%s\n",ptr); ptr++;
printf("%s\n",ptr); }
Samco systems, amco systems ---178 #include<stdio.h> main() { char s1[]="Ramco"; char s2[]="Systems"; s1=s2; printf("%s",s1); } ---179 #include<stdio.h> main() { char *p1; char *p2; p1=(char *) malloc(25); p2=(char *) malloc(25); strcpy(p1,"Ramco"); strcpy(p2,"Systems"); strcat(p1,p2); printf("%s",p1); }
180. For the following C program #define AND &&
#define ARRANGE (a>25 AND a<50) main() {int a = 30; if (ARRANGE) printf(“within range”); else printf(“out of range”); }
What is the output?
181. For the following C program #define AREA(x)(3.14*x*x) main()
{float r1=6.25,r2=2.5,a; a=AREA(r1);
printf(“\n Area of the circle is %f”, a); a=AREA(r2);
printf(“\n Area of the circle is %f”, a); }
What is the output?
Ans. Area of the circle is 122.656250 Area of the circle is 19.625000
182 What do the following statements indicate. Explain.
• Int (*p)[10] • Int *f() • Int (*pf)() • Int *p[10] 183. typedef struct{ char *; nodeptr next; } * nodeptr;
184
. int *x[](); means
expl: Elments of an array can't be functions. 185. struct list{
int x;
struct list *next; }*head;
the struct head.x =100 above is correct / wrong
l: Before using the ptr type struct variable we have to give memory to that . And also when ever the struct variable is ptr then we access the members by "->" operator. 186.o/p=? int i; i=1; i=i+2*i++; printf(%d,i); ans: 4 187. FILE *fp1,*fp2; fp1=fopen("one","w") fp2=fopen("one","w") fputc('A',fp1) fputc('B',fp2) fclose(fp1) fclose(fp2)} a.error b. c. d.
ans: no error. But It will over writes on same file.
188.#include<malloc.h> char *f() {char *s=malloc(8); strcpy(s,"goodbye")} main() { char *f(); printf("%c",*f()='A'); o/p=?
189) #define MAN(x,y) (x)>(y)?(x):(y) { int i=10;j=5;k=0; k= MAX(i++,++j) printf(%d %d %d %d,i,j,k)} 190) a=10;b=5; c=3;d=3; if(a<b)&&(c=d++) printf(%d %d %d %d a,b,c,d) else printf("%d %d %d %d a,b,c,d); : ... 191. what is o/p #include<stdarg.h> show(int t,va_list ptr1) { int a,x,i; a=va_arg(ptr1,int) printf("\n %d",a) } display(char) {int x; listptr;
va_star(otr,s); n=va_arg(ptr,int); show(x,ptr); } main() { display("hello",4,12,13,14,44); } a) 13 b) 12 c) 44 d) 14 ... 192.main() { int i = 10;
printf(" %d %d %d \n", ++i, i++, ++i); } 193.#include<stdio.h> main() { int *p, *c, i; i = 5; p = (int*) (malloc(sizeof(i))); printf("\n%d",*p); *p = 10; printf("\n%d %d",i,*p); c = (int*) calloc(2); printf("\n%d\n",*c); }
194.#define MAX(x,y) (x) >(y)?(x):(y) main() { int i=10,j=5,k=0; k= MAX(i++,++j); printf("%d..%d..%d",i,j,k); }
195.#include <stdio.h> main() { enum _tag{ left=10, right, front=100, back}; printf("left is %d, right is %d, front is %d, back is %d",left,right,front,back); }
196.main() { int a=10,b=20; a>=5?(b=100):(b=200); printf("%d\n",b); }
197.#define PRINT(int) printf("int = %d ",int) main() { int x,y,z; x=03;y=02;z=01; PRINT(x^x); z<<=3;PRINT(x); y>>=3;PRINT(y); }
199. supposing thaty each integer occupies 4 bytes and each charactrer 1 byte , what is the output of the following programme?
#include<stdio.h> main()
{
int a[] ={ 1,2,3,4,5,6,7}; char c[] = {' a','x','h','o','k'};
printf("%d\t %d ", (&a[3]-&a[0]),(&c[3]-&c[0])); }
ans : 12 3
200. what is the output of the program? #include<stdio.h> main() { struct s1 {int i; }; struct s2 {int i; }; struct s1 st1; struct s2 st2; st1.i =5; st2 = st1; printf(" %d " , st2.i); } ans: error
expl: diff struct variables should not assigned using "=" operator. 201.what is the output of the program?
#include<stdio.h> main() { int i,j; int mat[3][3] ={1,2,3,4,5,6,7,8,9}; for (i=2;i>=0;i--) for ( j=2;j>=0;j--) printf("%d" , *(*(mat+j)+i)); } ans : 9 6 3 8 5 2 7 4 1 202 fun(n); }
int fun( int n) {
int i;
for(i=0;i<=n;i++) fun(n-i);
printf(" well done"); }
howmany times is the printf statement executed for n=10?
ans: zero
expl: Befire reaching to printf statement it will goes to infinite loop.
203.what is the output of the program? main() { struct emp{ char emp[]; int empno; float sal; };
struct emp member = { "TIGER"};
printf(" %d %f", member.empno,member.sal);
If array size given ans is 0, 0.00
204. output of the program?
# define infiniteloop while(1) main() { infiniteloop; printf("DONE"); } ans: none
expl: infiniteloop in main ends with ";" . so loop will not reach end; and the DONE also will not print.
205 output of the program? main() { int a=2, b=3; printf(" %d ", a+++b); } ans:5
expl: here it evaluates as a++ + b. 206. output of the program? #define prn(a) printf("%d",a)
#define print(a,b,c) prn(a), prn(b), prn(c) #define max(a,b) (a<b)? b:a
main() { int x=1, y=2; print(max(x++,y),x,y); print(max(x++,y),x,y); } ans: 3 4 2
207. which of the following is the correct declaration for the function main() ? ans: main( int , char *[])
208. if ptr is defined as int *ptr[][100];
which of the following correctly allocates memory for ptr? ans: ptr = (int *)(malloc(100* sizeof(int));
209 the function strcmp(str1,str2) returns 210. int *x[](); means
211.#define PRINT(int) printf("int=%d",int); main() { int x,y,z; x=03;y=-1;z=01; PRINT(x^x); z<<=3;PRINT(x); y>>=3;PRINT(y);
}
212. struct list{ int x;
struct list *next; }*head;
the struct head.x =100 above is correct / wrong 213. '-'=45 '/'=47 printfr(%d/n,'-','-','-','-','/','/','/'); o/p =? 214.o/p=? int i; i=1; i=i+2*i++; printf(%d,i); 215.{ ch='A'; while(ch<='F'){ switch(ch){ case'A':case'B':case'C':case'D':ch++;continue; case'E':case'F':ch++; } putchar(ch); } }
a)ABCDEF b.EFG c.FG d.error 216. FILE *fp1,*fp2; fp1=fopen("one","w") fp2=fopen("one","w") fputc('A',fp1) fputc('B',fp2) fclose(fp1) fclose(fp2)} a.error b. c. d.
217 int a=1; b=2; c=3; *pointer; pointer=&c; a=c/*pointer; b=c; printf("a=%d b=%d",a,b); a. a=1 b=3 b a=3 b=3 c 3 2 d. error 218.#include<malloc.h> char *f() { char *s=malloc(8); strcpy(s,"goodbye") } main() { char *f()_; printf("%c",*f()='A'); } o/p=? 219. int sum(n) int n; if(n<1)return n; else return(n+sum(n-1)) a 10 b 16 c 14 d 15
220. when a function is recursively called all , automatic variables are a. stored in stack b . c. d 221) #define MAN(x,y) (x)>(y)?(x):(y)
{ int i=10;j=5;k=0; k= MAN(i++,++j) printf(%d %d %d %d,i,j,k) } 222) a=10;b=5; c=3;d=3; if(a<b)&&(c=d++) printf(%d %d %d %d a,b,c,d) else printf("%d %d %d %d a,b,c,d); : ... 223 what is o/p #include<stdarg.h> show(int t,va_list ptr1) { int a,x,i; a=va_arg(ptr1,int) printf("\n %d",a) } display(char) {int x; listptr; va_star(otr,s); n=va_arg(ptr,int); show(x,ptr); } main() { display("hello",4,12,13,14,44); } a) 13 b) 12 c) 44 d) 14 ...
224. if the following program (my prog) main(int size of ,char *arg[])
{ while(size of arg) printf("%s",arg[--size of arg) }
is run from the command line as myprog jan feb mar apr what would be the o/p
a)myprog jan,feb,mar,apr b)rev c)jan,feb,mar,apr d)error ... 225.what is o/p main() {int i=3; while(i--) { int i=100 i--; printf("%d..",i); } } a) infinite loop b) error c) 99..99..99..99 d) 3..22..1.. ... 226)what is the o/p of the program main()
{ int rows=3,colums=4; int a[rows][colums]={1,2,3,4,5,6,7,8,9,10,11,12}; i=j=k=99; for(i=0;i<rows;i++) for(j=0;j<colums;j++) if(a[k][j]<k) k=a[i][j]; printf("%d\n",k);
227. If a = 1, b = 2, c = 3...z = 26 what is the value of p+q+r ? (a)33 (b)51 (c)52 (d)48 Ans. B 228. (x-a)(x-b)(x-c)....(x-z) = ? (a) 1 (b) -1 (c) 0 (d) Can't be determined Ans. C
229. If a = 1, b = 2, c = 3...z = 26 what is the value of p+q+r ? (a)33 (b)51 (c)52 (d)48 Ans. B 230 VOIDMAIN() { INTD=5; PRINTF("%F",D); } ANS: UNDEFINED 231. VOIDMAIN() { INTI; FOR(I=1;I<4,I++) SWITCH(I)
CASE 1: PRINTF("%D",I);BREAK;
{
CASE 2:PRINTF("%D",I);BREAK; CASE 3:PRINTF("%D",I);BREAK;
}
SWITCH(I) CASE 4:PRINTF("%D",I);
} ANS: 1,2,3,4 232. VOIDMAIN() { CHAR *S="\12345S\N"; PRINTF("%D",SIZEOF(S)); } ANS: 6 233 VOIDMAIN() {
SIGNEDJ=-1; /* CHARK= -1 => K=65535 */
/* UNSIGNEDORSIGNEDINTK= -1 =>K=65535 */ IF(I<J) PRINTF("LESS"); ELSE IF(I>J) PRINTF("GREATER"); ELSE IF(I==J) PRINTF("EQUAL"); } ANS: LESS 234 VOIDMAIN() { FLOATJ; J=1000*1000; PRINTF("%F",J); } 1. 1000000 2. OVERFLOW 3. ERROR 4. NONE ANS: 4 235. INTF() VOIDMAIN() { F(1); F(1,2); F(1,2,3); }
F(INTI,INTJ,INTK)
{
PRINTF("%D %D %D",I,J,K);
}
WHATARETHENUMBEROFSYNTAXERRORSINTHEABOVE?
ANS: NONE. 236. VOIDMAIN() { INTI=7; PRINTF("%D",I++*I++); } ANS: 56 237. #DEFINEONE 0 #IFDEFONE
PRINTF("ONEISDEFINED ");
#IFNDEFONE
PRINTF("ONEISNOTDEFINED ");
ANS: "ONEISDEFINED"
238.
VOIDMAIN()
{
INTCOUNT=10,*TEMP,SUM=0; TEMP=&COUNT;
*TEMP=20; TEMP=&SUM;
*TEMP=COUNT;
PRINTF("%D %D %D ",COUNT,*TEMP,SUM);
} ANS: 20 20 20 239. MAIN() { STATICI=3; PRINTF("%D",I--); RETURNI>0 ? MAIN():0; } ANS: 321 240. CHAR *FOO() { CHARRESULT[100]);
STRCPY(RESULT,"ANYTHINGISGOOD"); RETURN(RESULT); } VOIDMAIN() { CHAR *J; J=FOO() PRINTF("%S",J); } ANS: ANYTHINGISGOOD. 241. VOIDMAIN() {
CHAR *S[]={ "DHARMA","HEWLETT-PACKARD","SIEMENS","IBM"}; CHAR **P; P=S; PRINTF("%S",++*P); PRINTF("%S",*P++); PRINTF("%S",++*P); }
ANS: "HARMA" (P->ADD(DHARMA) && (*P)->HARMA)
"HARMA" (AFTERPRINTING, P->ADD(HEWLETT-PACKARD) &&(*P)-HARMA) "EWLETT-PACKARD"
242 GIVENTHEFOLLOWINGSTATEMENT
ENUMDAY = { JAN = 1 ,FEB=4, APRIL, MAY}
WHATISTHEVALUEOFMAY?
(A) 4
(B) 5
(C) 6
(D) 11
(E) NONEOFTHEABOVE
243. FINDTHEOUTPUTFORTHEFOLLOWING C PROGRAM MAIN
{INTX,J,K; J=K=6;X=2; X=J*K;
PRINTF("%D", X);
FNF(X)
{ IF(X<=0) RETURN; ELSEF(X-1)+X;
}
245. FINDTHEOUTPUTFORTHEFOLLOWING C PROGRAM I=20,K=0; FOR(J=1;J<I;J=1+4*(I/J)) {K+=J<10?4:3; } PRINTF("%D", K); ANS. K=4
246. FINDTHEOUTPUTFORTHEFOLLOWING C PROGRAM INTI =10 MAIN() {INTI =20,N; FOR(N=0;N<=I;) {INTI=10; I++; } PRINTF("%D", I); ANS. I=20
247. FINDTHEOUTPUTFORTHEFOLLOWING C PROGRAM INTX=5;
Y= X&Y
248.FINDTHEOUTPUTFORTHEFOLLOWING C PROGRAM
Y=10;
IF( Y++>9 && Y++!=10 && Y++>10)
{PRINTF("%D", Y); ELSE
PRINTF("%D", Y);
} ANS. 13
249. FINDTHEOUTPUTFORTHEFOLLOWING C PROGRAM F=(X>Y)?X:Y
A) FPOINTSTOMAXOFXANDY B) FPOINTSTOMINOFXANDY C)ERROR
ANS. (A)
250)WHATISTHESIZEOF(LONGINT)
(A) 4 BYTES
(B) 2 BYTES
(C) COMPILERDEPENDENT
(D) 8 BYTES
251. WHICHOFTHEFUNCTIONOPERATORCANNOTBEOVERLOADED
(B) ?:
(C) ==
(D) *
252. FINDTHEOUTPUTFORTHEFOLLOWING C PROGRAM MAIN() {INTX=2,Y=6,Z=6; X=Y==Z; PRINTF(%D",X) } (C) BOTH E & F (D) B (E) BOTH B & C ANS. (B) 253 main() { int x=10,y=15; x=x++; y=++y; printf("%d %d\n",x,y); } 254 int x; main() { int x=0; { int x=10; x++; change_value(x); x++; Modify_value(); printf("First output: %d\n",x); } x++; change_value(x); printf("Second Output : %d\n",x); Modify_value(); printf("Third Output : %d\n",x); } Modify_value() { return (x+=10); } change_value() { return(x+=1); } 255 main() { int x=20,y=35; x = y++ + x++; y = ++y + ++x; printf("%d %d\n",x,y); } 256 main() { char *p1="Name"; char *p2; p2=(char *)malloc(20); while(*p2++=*p1++); printf("%s\n",p2); }
257 main() {
int x=5;
printf("%d %d %d\n",x,x<<2,x>>2); }
258 #define swap1(a,b) a=a+b;b=a-b;a=a-b; main() { int x=5,y=10; swap1(x,y); printf("%d %d\n",x,y); swap2(x,y); printf("%d %d\n",x,y); }
259 int swap2(int a,int b) { int temp; temp=a; b=a; a=temp; return; } 260 main() {
char *ptr = "Ramco Systems"; (*ptr)++; printf("%s\n",ptr); ptr++; printf("%s\n",ptr); } 261 #include<stdio.h> main() { char s1[]="Ramco"; char s2[]="Systems"; s1=s2; printf("%s",s1); } 262 #include<stdio.h> main() { char *p1; char *p2; p1=(char *) malloc(25); p2=(char *) malloc(25); strcpy(p1,"Ramco"); strcpy(p2,"Systems"); strcat(p1,p2); printf("%s",p1); } 263 ) main() { char a[2]; *a[0]=7; *a[1]=5; printf("%d",&a[1]-a) ANS:
ans may be 1.(illegal initialization) 264)
#include<stdio.h> main(){
char *b="hellow"; char c[5]="hellow"; printf("%s %s %s ",a,b,c); printf(" ",sizeof(a),sizeof(b),sizeof(c)); } (ans is hellow,hellow,hellow 6,2,5 ) 265) #include<stdio.h> main() float value=10.00; printf("%g %0.2g %0.4g %f",value,value,value,value) } (ans is 10,10,10,10.000000) 266) #include<stdio.h> void function1; int i-value=100; main() { i-value=50; function1;
printf("i-value in the function=",i-value); printf("i-value after the function=",i-value); }
printf("i-value at the end of main=",i-value); functioni()
i-value=25;
THIS IS ROUGH IDEA OF THE PROGRAM ANS ARE
1)i-value in the function=25; 2)i-value after the function=50; 3)i-value at the end of the main=100; 267) main() { funct(int n); { switch(n) case1: m=2; break; case2: m=5; break; case3: m=7; break; default: m=0; }
THIS IS ROUGH IDEA: (ANS:Out put is m=0)
268. OUTPUTOFTHEFOLLOWINGPROGRAMIS MAIN()
{INTI=0;
FOR(I=0;I<20;I++)
{SWITCH(I) CASE 0:I+=5;
CASE 1:I+=2; CASE 5:I+=5; DEFAULTI+=4; BREAK;} PRINTF("%D,",I); } } A) 0,5,9,13,17 B) 5,9,13,17 C) 12,17,22 D) 16,21 E) SYNTAXERROR ANS. (D)
269. WHATISTHEOUPTUTINTHEFOLLOWINGPROGRAM MAIN() {CHARC=-64; INTI=-32 UNSIGNEDINTU =-16; IF(C>I) {PRINTF("PASS1,"); IF(C<U) PRINTF("PASS2"); ELSE PRINTF("FAIL2"); } ELSE PRINTF("FAIL1); IF(I<U) PRINTF("PASS2"); ELSE PRINTF("FAIL2") } A) PASS1,PASS2 B) PASS1,FAIL2 C) FAIL1,PASS2 D) FAIL1,FAIL2 E) NONEOFTHESE ANS. (C)
270. WHATWILLTHEFOLLOWINGPROGRAMDO? VOIDMAIN() { INTI; CHARA[]="STRING"; CHAR *P="NEW SRING"; CHAR *TEMP; TEMP=A; A=MALLOC(STRLEN(P) + 1); STRCPY(A,P); //LINENUMBER:9// P = MALLOC(STRLEN(TEMP) + 1); STRCPY(P,TEMP);
PRINTF("(%S, %S)",A,P); FREE(P);
FREE(A);
} //LINENUMBER 15//
A) SWAPCONTENTSOFP & AANDPRINT:(NEWSTRING, STRING) B) GENERATECOMPILATIONERRORINLINENUMBER 8
C) GENERATECOMPILATIONERRORINLINENUMBER 5 D) GENERATECOMPILATIONERRORINLINENUMBER 7
E) GENERATECOMPILATIONERRORINLINENUMBER 1
ANS. (B)
271. WHATWILLBETHERESULTOFTHEFOLLOWINGPROGRAM ? CHAR *GXXX() {STATICCHARXXX[1024]; RETURNXXX; } MAIN() {CHAR *G="STRING"; STRCPY(GXXX(),G); G = GXXX(); STRCPY(G,"OLDSTRING"); PRINTF("THESTRINGIS : %S",GXXX()); } A) THESTRINGIS : STRING B) THESTRINGIS :OLDSTRING C) RUNTIMEERROR/COREDUMP D) SYNTAXERRORDURINGCOMPILATION E) NONEOFTHESE
ANS. (B)
272. WHATWILLBERESULTOFTHEFOLLOWINGPROGRAM? VOIDMYALLOC(CHAR *X, INTN)
{X= (CHAR *)MALLOC(N*SIZEOF(CHAR)); MEMSET(X,\0,N*SIZEOF(CHAR));
}
MAIN()
{CHAR *G="STRING"; MYALLOC(G,20);
STRCPY(G,"OLDSTRING"); PRINTF("THESTRINGIS %S",G);
}
A) THESTRINGIS : STRING B) RUNTIMEERROR/COREDUMP C) THESTRINGIS : OLDSTRING D) SYNTAXERRORDURINGCOMPILATION E) NONEOFTHESE
273. WHATWILLBETHERESULTOFTHEFOLLOWINGPROGRAM? MAIN() {CHARP[]="STRING"; INTX=0; IF(P=="STRING") {PRINTF("PASS 1"); IF(P[SIZEOF(P)-2]=='G') PRINTF("PASS 2"); ELSE PRINTF("FAIL 2"); } ELSE { PRINTF("FAIL 1"); IF(P[SIZEOF(P)-2]=='G') PRINTF("PASS 2"); ELSE PRINTF("FAIL 2");
} } A) PASS 1, PASS 2 B) FAIL 1, FAIL 2 C) PASS 1, FAIL 2 D) FAIL 1, PASS 2
E) SYNTAXERRORDURINGCOMPILATION
274. WHICHOFTHECHOICESISTRUEFORTHEMENTIONEDDECLARATION ? CONSTCHAR *P;
AND
CHAR * CONSTP;
A) YOUCAN'TCHANGETHECHARACTERINBOTH
B) FIRST : YOUCAN'TCHANGETHECHARACTERR & SECOND : YOUCAN;TCHANGETHEPOINTER C) YOUCAN'TCHANGETHEPOINTERINBOTH
D) FIRST : YOUCAN'TCHANGETHEPOINTER & SECOND : YOUCAN'TCHANAGETHECHARACTER E) NONE
275. THEREDIRECTIONOPERATORS > AND >> A) DOTHESAMEFUNCTION
B) DIFFER : > OVERWRITES, WHILE >> APPENDS
C) DIFFER : > ISUSEDFORINPUTWHILE >> ISUSEDFOROUTPUT
D) DIFFER : > WRITETOANYFILEWHILE >> WRITEONLYTOSTANDARDOUTPUT E) NONEOFTHESE
ANS. (B)
276. THECOMMANDGREPFIRSTSECONDTHIRD /USR/YOU/MYFILE
A) PRINTSLINESCONTAININGTHEWORDSFIRST, SECONDORTHIRDFROMTHEFILE /USR/YOU/MYFILE B) SEARCHESFORLINESCONTAININGTHEPATTERNFIRSTINTHEFILES
SECOND, THIRD, AND /USR/YOU/MYFILEANDPRINTSTHEM
C) SEARCHESTHEFILES /USR/YOU/MYFIELANDTHIRDFORLINESCONTAININGTHEWORDSFIRSTORSECONDANDPRINTS THEM
D) REPLACESTHEWORDFIRSTWITHTHEWORDSECONDINTHEFILESTHIRDAND /USR/YOU/MYFILE E) NONEOFTHEABOVE
ANS. (B)
277. Find the output for the following C program
int array[4][4] = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16}; for (i=2;i<0;i--)
for (j=2;j<=0;j--) printf(“%d”, arr[i][j]);
278. Find the output for the following C program #include<stdio.h> void main() {int i,x,sum=0; int arr[6]=[1,2,3,4,5,6] for (i=0;i<4;i++) sum+ = func(arr[i]); printf(“%d”, sum); } func(int x) { int val,x; val = 2; return(x+ val++); }
279. For the following C progralm int d=0; for(int i=0;i<31;i++) for(int j=0;j<31;j++) for(int k=0;k<31;k++) if (((i+j+k) % 3)==0) d=d+1;
Find value of d 280. char *a[2]; int const *p; int *const p;
struct new { int a;int b; *var[5] (struct new)}
Describe the statements in the above given construct ? 281. f() { int a=2; f1(a++); } f1(int c) { printf("%d", c); }
What is the value of c ? 282. f1() { f(3); } f(int t) { switch(t); { case 2: c=3; case 3: c=4; case 4: c=5; case 5: c=6; default: c=0; }
What is the value of c?
283. What is the fallacy in the following program segment ? int *f1() { int a=5; return &a; } f() int *b=f1() int c=*b; }
284). Give the C language equivalents of the following a)Function returning an int pointer
b)Function pointer returning an int pointer c)Function pointer returning an array of integers
d)Array of function pointer returning an array of integers 285. Find the fallacy in the following program segment? int a;
short b; b=a;
286) Define function ? Explain arguments in functions ? 287. How does C pass variables to a function ?
288. Explain the following program segment. f(){
int *b; *b=2; }
289. Explain binary trees and their use ?
290. Draw the diagram showing the function stack, illustrating the variables that were pushed on the stack at the point when function f2 has been introduced .
type def struct
{ double x,double y} point; } main( int argc, char *arg[3]) { double a; int b,c; f1(a,b); } f1(double x, int y) {point p; stack int n; f2(p,x,y) }
f2(point p, double angle) { int i,j,k,int max; }
291. What is the mistake in the following program segment ? f() { int a; void c; f2(&c,&a);} 292 a=0; b=(a=0)?2:3;
a) What will be the value of b and why ?
b) If in first statement a=0 is replaced by a = -1, b= ? c) If in second statement a=0 is replaced by a = -1, b=? 293. char *a[2];
int const *p; int *const p;
struct new { int a;int b; *var[5] (struct new)}
Describe the statements in the above given construct ? 294. f() { int a=2; f1(a++); } f1(int c) { printf(“%d”, c); }
What is the value of c ? 295. f1() { f(3); } f(int t) { switch(t); { case 2: c=3; case 3: c=4; case 4: c=5; case 5: c=6; default: c=0; }
296 What is the value of c?
. Which of the following about the following two declaration is true
i ) int *F() ii) int (*F)() Choice :
b) The first is a correct declaration and the second is wrong
c) The first declaraion is a function returning a pointer to an integer and the
second is a pointer to function returning int d) Both are different ways of declarin pointer to a function
Answer : c
297. What are the values printed by the following program?
#define dprint(expr) printf(#expr "=%d\n",expr) main() { int x=7; int y=3; dprintf(x/y); } Choice:
a) #2 = 2 b) expr=2 c) x/y=2 d) none Answer: c
298. Which of the following is true of the following program main() { char *c; int *p; c =(char *)malloc(100); ip=(int *)c; free(ip); }
ans: The code functions properly releasing all the memory allocated
299.output of the following. main() { int i; char *p; i=0X89; p=(char *)i; p++; printf("%x\n",p); } ans:0X8A
300. When an array is passed as parameter to a function, which of the following
statement is correct choice:
a) The function can change values in the original array
b) In C parameters are passed by value. The funciton cannot change the original
c) It results in compilation error when the function tries to access the
elements in the array
d) Results in a run time error when the funtion tries to access the elements in
the array Answer: a
301. The type of the controlling statement of a switch statement cannot be of the
type
a) int b) char c) short d)float e) none Answer : d
302.What is the value of the statement (3^6) + (a^a)? a) 3 b) 5 c) 6 d) a+18 e) None
Answer : b
303. What is the value assigned to the variable X if b is 7 ?
X = b>8 ? b <<3 : b>4 ? b>>1:b; a) 7 b) 28 c) 3 d) 14 e) None ans: c
304. Which is the output produced by the following program main() { int n=2; printf("%d %d\n", ++n, n*n); } a) 3,6 b) 3,4 c) 2,4 d) cannot determine Answer : b
305. What is th output of the following program? int x= 0x65; main() { char x; printf("%d\n",x) }
a) compilation error b) 'A' c) 65 d) unidentified 306. What is the output of the following program main() { int a=10; int b=6; if(a=3) b++; printf("%d %d\n",a,b++); } a) 10,6 b)10,7 c) 3,6 d) 3,7 e) none Answer : d
main() {
enum Months {JAN =1,FEB,MAR,APR}; Months X = JAN;
if(X==1) {
printf("Jan is the first month"); }
}
a) Does not print anything b) Prints : Jan is the first month c) Generates compilation error d) Results in runtime error Answer: b
308. What is the output of the following program? main()
{
char *src = "Hello World"; char dst[100]; strcpy(src,dst); printf("%s",dst); } strcpy(char *dst,char *src) { while(*src) *dst++ = *src++; }
a) "Hello World" b)"Hello" c)"World" d) NULL e) unidentified
Answer: may be d
309. What is the output of the following program? main() { int l=6; switch(l) { default : l+=2; case 4: l=4; case 5: l++; break; } printf("%d",l); } a)8 b)6 c)5 d)4 e)none Answer : c
310. What is the output of the following program? main() { int x=20; int y=10; swap(x,y); printf("%d %d",y,x+2); } swap(int x,int y) { int temp; temp =x; x=y; y=temp; }
a)10,20 b) 20,12 c) 22,10 d)10,22 e)none Answer:d
311. What is the output of the following problem ? #define INC(X) X++ main() { int X=4; printf("%d",INC(X++)); }
a)4 b)5 c)6 d)compilation error e) runtime error Answer : d
312. what can be said of the following struct Node {
char *word; int count; struct Node left; struct Node right; }
a) Incorrect definition
b) structures cannot refer to other structure c) Structures can refer to themselves. Hence the statement is OK
d) Structures can refer to maximum of one other structure
Answer :c
313. What is the size of the following union. Assume that the size of int =2, size of float =4 and size of char =1. Union Tag{ int a; flaot b; char c; }; a)2 b)4 c)1 d) 7 may be b
314) What is the output of the following program? (. has been used to indicate a
space) main() { char s[]="Hello,.world"; printf(%15.10s",s); } a)Hello,.World... b)....Hello,.Wor c)Hello,.Wor.... d)None of the above
315) Consider the following function written in c: #define NULL 0 char * index(sp,c) register char *sp,c; { do { if(*sp == c) return (sp); } while (*sp++); return NULL; }
The first argument sp, is a pointer to a C string. The second argument, c, is a character. This function searches for the character c, in the string. If it is found a pointer to that location is returned else NULL is returned.
This function works a) Always
b) Always, but fails when the first byte contains the character c c) works when c is a non NULL character only
d) Works only when the character c is found in the string answer: a
316) What is printed when this program is executed main() { printf ("%d\n",f(7)); } f(X) { if (x<= 4) return x; return f(--x); } a) 4 b) 5 c) 6 d) 7 answer: a
317) On a machine where pointers are 4 bytes long, what happens when the
following code is executed. main() { int x=0,*p=0; x++; p++; printf ("%d and %d\n",x,p); } a) 1 and 1 is printed b) 1 and 4 is printed c) 4 and 4 is printed d) causes an exception
318) Which of the following is the correct code for strcpy, that is used to copy the contents from src to dest? a) strcpy (char *dst,char *src)
{
while (*src) *dst++ = *src++; }
{
while(*dst++ = *src++) }
c) strcpy (char *dst,char *src) { while(*src) { *dst = *src; dst++; src++; } } d) strcpy(char *dst, char *src) { while(*++dst = *++src); } answer:b
319) Consider the following program main() { int i=20,*j=&i; f1(j); *j+=10; f2(j);
printf("%d and %d",i,*j); } f1(k) int *k; { *k +=15; } f2(x) int *x; { int m=*x,*n=&m; *n += 10; }
The values printed by the program will be a) 20 and 55
b) 20 and 45 c) 45 and 45 d) 45 and 55 e) 35 and 35
320) what is printed when the following program is compiled and executed?
int func (int x) { if (x<=0) return(1); return func(x -1) +x; } main() { printf("%d\n",func(5)); } a) 12 b) 16 c) 15
d) 11
321) Consider the following of c code in two files which will be linked together and executed . a.c ___ int i; main() { i = 30; f1(); printf("%d\n",i) } b.c ___ static int f1() { i+=10; }
which of the following is true ?
a) a.c will fail in compilation phase because f1() is not declared
b) b.c will fail in compilation because the variable i is not declared
c) will print 30 d) will print 40 e) a & b answer: e
322) Consider the following prg void funca (int *k)
{ *k += 20 }
void funcb (int *x) { int m=*x,*n = &m; *n+=10; } main() {
int var = 25,*varp=&var; funca(varp);
*varp += 10; funcb(varp);
printf ("%d and %d\n",var,*varp); }
The values printed when the above prg is complied and executed are: a) 20 and 55 b) 20 and 45 c) 45 and 55 d) 55 and 55 e) 35 and 35 answer: d
323. Given the following statement
enum day = { jan = 1 ,feb=4, april, may} What is the value of may?
(a) 4 (b) 5 (c) 6 (d) 11
(e) None of the above
324 Find the output for the following C program main {int x,j,k; j=k=6;x=2; x=j*k; printf("%d", x);
325. Find the output for the following C program fn f(x) { if(x<=0) return; else f(x-1)+x; }
326. Find the output for the following C program i=20,k=0; for(j=1;j<i;j=1+4*(i/j)) {k+=j<10?4:3; } printf("%d", k); Ans. k=4
327. Find the output for the following C program int i =10 main() {int i =20,n; for(n=0;n<=i;) {int i=10; i++; } printf("%d", i); Ans. i=20
328.Find the output for the following C program Y=10;
if( Y++>9 && Y++!=10 && Y++>10) {printf("%d", Y); else printf("%d", Y); } Ans. 13
329. Find the output for the following C program f=(x>y)?x:y
a) f points to max of x and y b) f points to min of x and y c)error
Ans. (a)
330. Find the output for the following C program main() {int x=2,y=6,z=6; x=y==z; printf(%d",x) }
331. What is the output of the following program main() { int var=25,varp; varp=&var; varp p = 10; fnc(varp) printf("%d%d,var,varp); }
(a) 20,55 (b) 35,35 (c) 25,25 (d)55,55
332) #define f(x,y) x##y void main()
{
printf("%s",f("This","This is")); }
a) This b)is c)ThisThis is d) None ans : c 333) #define INC(x) x++ void main() { int a = 1; printf("%d",INC(a++)); }
a) 1 b) 2 c) 3 d) Program won't compile ans : d 334) Assume the size of the int to be 4
#define NULL 0 void main() {
int i=0,*p = NULL; i++;p++;
printf("%d %d",i,p); }
a) 1 4 b) 4 1 c) 4 4 d)1 1 ans : a
335) In ANSI C the output of the following C code segment is I = 5; a[5] = 5; a[6] = 11; a[7] = 12; a[I] = I++; printf("%d %d",a[5],a[6]);
a) 6 11 b) 5 12 c) 5 6 d)None ans : d (answer is 5 11) 336 (3^2) + (a^a) is equal to
a) 0 b) 1 c) 3 d) Data Insufficient ans:b(^ bitwise Exclusive OR) 337) void main() { int x=8; clrscr(); x = x > 10 ? x<<2 : x>7 ? x>>2 : x<<3; printf("%d",x); } a) 1 b) 2 c) 4 d) None ans : b 338) The value of a and b after assignment are
int a,b; a = (10,15); b = 10,15; a) 10 15 b) 15 10 c)10 10 d) 15 15 ans : b b) 339) f(int x) { if(x<=0) return 1; return f(x-1) + x; } void main()
{
printf("%d",f(7)); }
a) 28 b) 29 c) 15 d) None ans : b 340) In C arguments could be passed only
a) by reference b) by value c) by name d) reference & value ans : d 341) typedef struct { char * str; NODEF next; } * NODEF;
a)works only in C b) works only in C++ c) works in C & C++ d) Won't compile in both C & C++ ans : d
342) #define NULL 0 char * f(str,c) register char * str,c; { while(*str) if(*str++ == c) return str; return NULL; }
a) the above function will always work
b) won't work for c = NULL c) won't work if c is not found d) won't work if c is the first character ans : a
343) void main() { int x = 10, y=6,z=4; x=y==z; printf("%d",x); }
a) 0 b) 1 c)6 d) compiler Error e) None of the above ans : a
344) static functions in C could be called only
a) after decleration b)after defination c) after decleration and before defination d) anywhere ans : d 345) there are 2 files called a.c and b.c
a.c int i; void main() { i = 10; f1(); printf("%d",i); } b.c static void f1() { i += 15; }
a) a.c won't compile as f1() is not declered b) b.c won't compile as i is not declered c) prints 25 d) prints 10 ans : a 346)
void f(int *x,int y) {
int temp; temp = *x; *x = y; y = temp; } void f1(int *x) { int *a,b; b = *x; a = &b; *a += 10; } void main() { int a =10,b=5; int *c; c = &a; f(c,b); f1(c); printf("%d %d",a,b); } a) 5 5 b)10 5 c)15 10 d)None ans : a 347) void f(int *x) { *x += 10; }
void f1(int *y) { int temp,*pt; temp = *y; pt = &temp; *pt += 15; } void main() { int x = 10; f(&x); f1(&x); printf("%d",x); }
a)35 a)25 c)20 d)10 ans : c
348) expression in switch statement can not accept the data type a) int b) char c) short d) float ans : d
349) Which of the following is not a basic data type
a) char b) char * c) float d) double ans : b (check it out)
350)
f(int a,int b) {
if(a<b) return &a; return &b; } void main() { int a=10,b=5,*c; c = f(b,a); printf("%d",*c); }
a) compile error b) 10 c) 5 d) Junk ans : c 351) which one could be a substitute for strcpy()
a) while(*str++ = *dtr++); b) while(*++str)*str = *++dtr; c) while(*++str = *++dtr); d)None ans : a
352) consider the structure for double linked list struct d_list
{
int a;
struct d_list * next; struct d_list * prev; };
assume NULL has been assigned for first link of the list's prev pointer and the next pointer of the last link
353.enum day = { jan = 1 ,feb=4, april, may} what is the value of may?
a)4 b)5 c)6 d)11 e)none of the above
354.main { int x,j,k; j=k=6;x=2; ans x=1 x=j*k; printf("%d", x); 355. fn f(x) { if(x<=0) return; ans fn(5) ....? else f(x-1)+x; } 356. i=20,k=0; for(j=1;j<i;j=1+4*(i/j)) { k+=j<10?4:3; } .main() { printf("%d",printf("HelloSoft")); } Output? 357.case 1: case 2:
typedef Struct { typedef Struct { int a; char p;
char b; int q; int d; char k; char e; int l; }A; }A;
Assuming 'packing' is not enabled, which case will give an error of Sizeof(A) less.
358.main() { int i=3; printf("%d %d %d",i++,i,++i); } 359.main() { int i=10; int j,k=5; int a[10]; for(j=0;j<10;j++) a[j]=(i+k)+(i*k); }
360 .main() { int *p=0x100; int *q=0x100; int k=p*q; printf("%x\n",k); } Output ? 361.Char* foo(Str...) { char str[4]; strcpy(str,"HelloSoft"); return str; } Output? 362 .int a[10][20][30][40]; int *p
How to access an element of a using p? 363.main() { int i=10; if(i>20) if(i==10) print("Hi"); else printf("Bye"); } Output ? 364.main() { float f; int i;
//something like this i do not remember these 4 questions exactly
f=(float *)malloc(sizeof((float *)*4)); }
Some Question was asked i do not remenber .
365.One more Question as above asking Where will the variables be stored ? printf("%d", k); ans k=4 366. int i =10 main() { int i =20,n; for(n=0;n<=i;) { int i=10 i++; }
printf("%d", i); ans i=20 367. int x=5;
y= x&y
( MULTIPLE CHOICE QS) ans : c
368. Y=10;
if( Y++>9 && Y++!=10 && Y++>10) printf("... Y);
else printf("".... ) ans : 13
369. f=(x>y)?x:y