C Programming Theory Quiz - SOLUTION
C Programming Theory Quiz - SOLUTION
Answer ALL questions, each carry One Mark, there may be multiple Answers, No Marks for partial Answers
Name:
1. Which of the following keywords is used to declare a variable in C?
A. define B. int C. var D. print
2. Which of the following operators checks if two conditions are both true?
A. == B. != C. || D. &&
3. What is the output of the following code?
int x = 10;
x++;
printf("%d", x);
A. Error B. 10 C. 9 D. 11
7. To pass a variable by reference to a function, we use the & operator before the variable name, called address
passing.
8. Recursion is a technique where a function calls itself.
9. What is the advantage of using bit shifts over multiplication and division in certain situations?
A. They are always faster. B. They can be used on single bits directly.
C. They are more accurate for floating-point numbers. D. They require less memory usage.
10. Which function is used to dynamically allocate memory in C?
A. malloc() B. calloc() C. realloc() D. All of the above
int main() {
char *p = 0;
*p = ’a’;
printf("%c", *p);
return 0;}
A. It will print ’a’ B. It will print 0 C. Compile time error D. Runtime error
main(){
char *p = "Computer Programming";
p[0] = ’c’;
p[2] = ’p’;
printf("%s", p);}
A. Computer Programming B. Copputer Programming C. Compile time error D. Run time error
15. What will be the output of the following C code?
void main(){
char *str = "";
do{
printf("hello");
} while (str);}
void main(){
int i = 0;
while (i < 10){
i++;
printf("hi\n");
while (i < 8){
i++;
printf("hello\n");}}}
A. hi is printed 8 times, hello 7 times and then hi 2 times B. hi is printed 10 times, hello 7 times
C. hi is printed once, hello 7 times D. hi is printed once, hello 7 times and then hi 2 times
17. What will be the output of the following C code?
void main(){
int x = 1, y = 0, z = 5;
int a = x && y || z++;
printf("%d %d", z, a);}
A. 6 0 B. 6 1 C. 5 0 D. 5 1
18. What will be the output of the following C code?
main() {
int i = 2; {
int i = 4, j = 5;
printf("%d %d", i, j);}
printf("%d %d", i, j); }
26. The following function computes the maximum value contained in an integer. Fill in the blank:
int main() {
int sum = 2 + 4 / 2 + 6 * 2;
printf("%d", sum);
return 0;
}
A. 2 B. 15 C. 16 D. 18
28. Assume that a character takes 1 byte. What is the output of the following program?
int main()
{
char str[20] = " ChandQuiz ";
printf ("%d", sizeof(str));
return 0;
}
A. 9 B. 10 C. 20 D. Garbage Value
void solve() {
int ch = 2;
switch(ch) {
case 1: printf("1 ");
case 2: printf("2 ");
case 3: printf("3 ");
default: printf("None");}}
int main(){
solve();
return 0;}
void solve() {
char s[] = "Hello";
printf("%s ", s);
char t[40];
strcpy(t, s);
printf("%s", t);}
int main() {
solve();
return 0;}
A. a=72 b=58 c=114 B. a=72 b=72 c=72 C. a=72 b=0 c=0 D. Syntax Error
32. What will be the output of the following program?
int auto m;
int main(){
m=120;
printf("m=%d",m);
return 0;}
int main(){
int x, y =32;
char z= ’A’;
x= y + z;
printf("%c %c %c",x,x+1,x+2);
return 0;}
int main(){
int x, y, w, z;
z=(x=3, y=5, y||x);
w= (z^y)<<x;
printf("%d %d", z, w);
return 0;}
strcmp("Calculator","Computer");
A. -1 B. 1 C. 0 D. NULL
39. Consider the following code. How many times will “A" be printed on the screen?
int main() {
int i,j;
for(i=10;i>0;i-=3)
for(j=0;j<10;j+=3)
printf("A");
return 0;}
A. 0 B. 12 C. 16 D. 20
40. Consider the following integer 2D array, which is stored in memory with the base address 1400. What would be the
address of the element 14? [Assume that an integer value takes 4 bytes of memory space.]
int a[3][5]={{1,2,3,4,5},{6,7,8,9,10},{11,12,13,14,15}};