C Programming Practice Set II (75 Questions)
01. What error would the following function give on compilation
f(int a,int b) { int a; a=20; return a; }
1) missing parenthesis in return statement
2) the function should be defined as int f(int a, int b)
3) redeclaration of a
4) none of the above
02. What would be the output of the following program
main() { int a=10; void f(); a=f(); printf("%d",a); } void f() { printf("hi"); }
1) 2
2) 3
3) error
4) none
03. What is the output of the following program
main() { int b; b=f(20); printf("%d",b); } int f(int a) { a > 10 ? return(40) : return(50); }
1) 40
2) 50
3) error
4) none
04. How many times the string will be printed
main() { printf("I have one brother"); main(); }
1) error
2) infinite number of times
3) 65535
4) till the stack does not overflow
05. What would be the output of the following program
#define SQR(x) x*x main() { int a; a=SQR(b+2); printf("%d",a); }
1) 144
2) b+2 * b+2
3) 32
4) garbage
06. What is the output of the following program
#define CUBE(x) (x*x*x) main() { int a,b=3; a=CUBE(++b); printf("%d %d",a,b); }
1) 27 3
2) 64 4
3) 216 6
4) none
07. What is the type of the variable abc according to the following definition
#define FLOATPTR float * FLOATPTR xyz,abc;
1) float
2) pointer to float
3) both
4) none
08. Which of the following is true
1) a header file should definetely have an extension .h
2) there is no error if a header file is included twice
3) a preprocessor can trap simple errors like missing declarations
4) NULL macro is defined in stdio.h
09. What is the output of the following program
#define BUS Train main() { printf("BUS"); }
1) BUS
2) Train
3) error
4) none
10. The following program results in
#define LOOP while(1) main() { LOOP printf("Hi"); }
1) error
2) infinite loop
3) prints Hi once
4) none
11. What is the output of the following program
#define MAX(a,b) (a>b?a:b) main() { int x; x=MAX(4+2,3+8); printf("%d",x); }
1) 6
2) 11
3) 17
4) error
12. What is the output of the following program
#define PRINT(int) printf("%d",int) main() { int x=2, y=3, z=4; PRINT(x); PRINT(y); PRINT(z); }
1) 2 3 4
2) 4 4 4
3) 4 3 2
4) error
13. What is the output of the following program
main() { printf("BBC ""world"); }
1) BBC
2) BBC world
3) error
4) none
14. What is the output of the following program
#define str(x) #x #define hstr(x) str(x) #define proper divide main() { char *name = hstr(proper); printf("%s",name); }
1) proper
2) hstr
3) divide
4) error
15. What is the output of the following
#define sum(xy) printf("f%xy",f,xy) main() { float a=3.5,b=5; sum(a+b); }
1) 8.5
2) error
3) a+b=8.5
4) none
16. What is the output of the following program
#define combine(s1,s2) s1 ## s2 float totalsales=2.5; printf("%f",combine(totalsales));
1) 2.5
2) totalsales
3) error
4) none
17. What is the output of the following program
main() { printf("%c", 'neelesh'); }
1) e
2) l
3) neel
4) error
18. Which of the following is true
1) void pointer cannot be used for arithmetic operations
2) *ptr++ and ++*ptr are the same
3) a structure cannot have pointer
4) we can have an array of bitfields
19. What would be the output of the following program
main() { char a[]="neelesh"; printf("%d %d",sizeof(a),sizeof(a)); }
1) 8 2
2) 7 1
3) 8 1
4) 8 8
20. What would be the output of the following program, if the array begins at address 5000.
main() { int abba[] = {6,4,7,3,3}; printf("%u %d",abba,sizeof(abba)); }
1) 5000 2
2) 5000 10
3) 5002 10
4) error
21. What would be the output of the following program
main() { float ff[20]={5,4,6}; printf("%u %u",ff,&ff); }
1) 8000 8000
2) 8000 5000
3) 8000 8004
4) negative values
22. What would be the output of the following program, if the array begins at the address 6000
main() { int abc[] = {3,4,5,4}; printf("%u %u",abc+1,&abc+1); }
1) 6001 6001
2) 6002 6002
3) 6002 7000
4) error
23. What would be the output of the following program
main() { int i[]="hello"; a="no hello"; printf("%d",strlen(a)); }
1) 5
2) 8
3) 9
4) error
24. What would be the output of the following program
main() { double x[]={2.3,3.4,4.4,5}; printf("%d",sizeof(x)/sizeof(x[1])); }
1) 2
2) 3
3) 8
4) error
25. What would be the output of the following program, if the array begins at the address 8000
main() { int b[3][4] = { 4,3,2,5,6,3,2,7,7,6,5,4}; printf("%u %u",b+1,&b+1); }
1) 8001 8001
2) 8002 8002
3) 8008 8024
4) 8008 8008
26. What is the output of the following program
main() { printf("kishore"+2); }
1) kishore
2) ki
3) shore
4) error
27. What is the output of the following program
main() { char s1[]="right",s2[]="right"; if(s1==s2) printf("yes"); else printf("no"); }
1) yes
2) no
3) error
4) none
28. What would be the output of the following program in C
main() { char xyz[4]="Bahu"; printf("%s",xyz); }
1) Bahu
2) error
3) cannot predict
4) none
29. What is the output of the following program
main() { int k=5; printf("%d %d",k,<=30,k=80); }
1) 1 1 80
2) 0 0 80
3) 5 30 80
4) none
30. What is the output of the following
main() { char ch='a'; printf("%d %d %d",ch,sizeof('a'),sizeof("hello")); }
1) 1 1 2 5
2) 1 2 2 6
3) 1 1 2 6
4) 1 2 2 5
31. What would be the output of the following program
main() { printf("%c","jayaram"[5]); }
1) a
2) r
3) error
4) jayaram
32. What is the output of the following program
main() { struct student { char *x; int age; }; struct student s1 = {"mahesh",21}; struct student s2=s1; printf("%s %d",s2.x); }
1) mahesh
2) garbage
3) error in assigning structure
4) none
33. What is the output of the following program
main() { struct student { char *x; int age; }; struct student s1 = {"mahesh",21}; struct student s2=s1; if(s1==s2) printf("hello"); }
1) hello
2) no output
3) error in assigning structure variables
4) error in comparing structure variables
34. Which of the following is false
1) structures can have a pointer to itself
2) structures can be passed as arguments in functions
3) bit fields of structures are used to save space in structures
4) the size of all the elements in an union should be same
35. What is the output of the following program
main() { union a { int x; char ch[2]; }; union a z1={2,3}; printf("%d %d",z1.x); }
1) 2
2) 3
3) initialization error
4) none
36. What is the output of the following program
main() { int k=9; const int *ptr; ptr=k; ptr=ptr-10; printf("%d",*ptr); }
1) 5
2) 10
3) error
4) none
37. What is the output of the following program
main() { int k=9; const int *ptr; ptr=k; printf("%d",*ptr); }
1) 9
2) garbage
3) error
4) none
38. Choose the correct answer
1) use of goto enhances the logical clarity of a code
2) use of goto makes the debugging task easier
3) use goto when you want to jump out of a nested loop
4) we can never use goto
39. Which is true about conditional compilation
1) it is taken care by the compiler
2) it is setting the compiler option conditionally
3) it is compiling based on condition
4) none of the above
40. C was primarily developed as
1) systems programming language
2) general purpose language
3) data processing language
4) none
41. C is a
1) high level language
2) low level language
3) high level language with low level features
4) none
42. The variables which can be accessed by all modules in a program are known as
1) local variables
2) internal variables
3) global variables
4) none
43. In what kind of storage structure for strings, one can easily insert, delete, concatenate and rearrange substrings
1) fixed length storage structure
2) variable length storage
3) linked list storage
4) array type storage
44. The variables which can be accessed by all modules in a program are known as
1) local variables
2) internal variables
3) global variables
4) none
45. In what kind of storage structure for strings, one can easily insert, delete, concatenate and rearrange substrings
1) fixed length storage structure
2) variable length storage
3) linked list storage
4) array type storage
46. What would be the output of the following program
main() { int i=1,j=0x20,k,l,m; k=i | j; l=i & j; m=i^j; printf("%d %d %d",i,j,k,l,m); }
1) 32 32 32 2 0
2) 0 0 0 0 0
3) 0 32 32 32 0
4) 32 32 32 32 32
47. What is the output of the following program
main() { unsigned int m=32; printf("%x",~m); }
1) ff
2) 0000
3) ffdf
4) ddfd
48. Which of the following is false
1) & operator is used for checking a particular bit is on or off
2) & operator is used for turning off a particular bit
3) | operator is used for putting a particular bit on
4) left shifting rotates the left most bits to the right end
49. What is the output of the following program
main() { unsigned int a=0xfffff; printf("%x",~a); }
1) ff
2) 0
3) 00ff
4) error
50. What would be the output of the following program
main() { unsigned char i=0x80; printf("%d",i<<1); }
1) 0
2) 256
3) 100
4) none
51. What is the output of the following program
main() { printf("%x",~(-1>>4)); }
1) ff
2) 0ff
3) 0000
4) depends on computer architecture
52. If the definition is given in the following way which is false
#define xyz char * xyz a,b;
1) a is a character pointer
2) b is a character pointer
3) b is character
4) error
53. What would be the output of the following program
main() { int y=128; const int x=y; printf("%d",x); }
1) 128
2) garbage
3) error
4) 0
54. What is the output of the following program
main() { int get() { return(30); } const int x=get(); printf("%d",x); }
1) 30
2) garbage
3) error
4) 0
55. What would be the output of the following program
main() { const int x=5; int *ptr; *ptr= &x; *ptr=10; printf("%d",x); }
1) 5
2) 10
3) error
4) garbage
56. What would be the output of the following program
main() { struct student { char rollno : 5; char name[20] : 6; }; printf("%d",sizeof(struct student)); }
1) 2
2) 22
3) 11
4) error
57. Which of the following is false about bit fields
1) there can be unnamed fields declared with size
2) one can scan the bit fields using scanf statement
3) bit fields can be arrayed
4) there can be unused bits in the words
58. What is the output of the following program
main() { float b=6.15529; printf("%6.2f",b); }
1) 6.16
2) 6.15
3) 00006.15
4) error
59. What is the output of the following program
main() { float d=8.7; printf("%0.0f",d); }
1) 8.7
2) 8
3) 0
4) error
60. What is the output of the following program
#include <stdio.h> main() { FILE *fp; fp=fopen("xyz","r"); }
1) fp points to the first character of the file
2) a structure which contains a char pointer which points to the first character of file
3) the name of the file
4) None
61. What is the output of the following program
main() { int x=4; printf("%d %d",x,x); }
1) x=4 4
2) x=4
3) 4 4
4) error
62. Which of the following statement is true
1) we can specify variable field width in scanf()
2) we can specify variable field width in printf()
3) a file written in text mode cannot be read in binary mode
4) we should not write a file without an intervening call to fflush(), fseek(), rewind()
63. Which of the following statement is true
1) the variable argc and argv are always local to main
2) C is superset of C++
3) C is not case sensitive
4) C is not free format
64. The maximum combined length of the command line arguments including the spaces between adjacent arguments is
1) 128 characters
2) 256 characters
3) 67 characters
4) depends on operating system
65. If the program (xyz) is run from the command line as xyz red green blue What is the output
main(int argc,char *argv[]) { while(argc) printf("%s",*argv++); }
1) xyz red green blue
2) xyz red green
3) blue green red xyz
4) garbage
66. What is the output of the following program
main() { const int x=5; int *ptr; *ptr= &x; ptr=10; printf("%d",x); }
1) 5
2) 10
3) error
4) none
67. In what kind of storage structure for strings, one can easily insert, delete, concatenate and rearrange substrings
1) fixed length storage structure
2) variable length storage
3) linked list storage
4) array type storage
68. What is the time complexity of linear search algorithm over an array of n elements
1) O(log n)
2) O(n)
3) O(n log n)
4) O(n²)
69. What is the time taken by binary search algorithm to search a key in a sorted array of n elements
1) O(log n)
2) O(n)
3) O(n log n)
4) O(1)
70. What is the time required to search are element in a linked list of length n
1) O(log n)
2) O(n)
3) O(1)
4) O(n log n)
71. What is the worst case time required to search a given element in a sorted linked list length n
1) O(1)
2) O(log n)
3) O(n)
4) O(n log n)
72. Consider a linked list of n elements. What is the time taken to delete the element which is the successor of the element pointed to by a given pointer
1) O(1)
2) O(log n)
3) O(n)
4) O(n log n)
73. Consider a linked list of n elements. What is the time taken to insert an element after an element pointed to by some pointer
1) O(1)
2) O(log n)
3) O(n)
4) O(n log n)
74. Which of the following operations is performed more efficiently by doubly linked list than by linear linked list
1) deleting a node whose location is given
2) searching an unsorted list for a given item
3) inserting a node after the node with a given location
4) traversing the list to process each node
75. Which data structure is needed to convert infix notations to postfix notation
1) linear list
2) queue
3) tree
4) stack
Submit Quiz