0% found this document useful (0 votes)
59 views4 pages

C Programming Theory Quiz - SOLUTION

Uploaded by

Harshit Jain
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
0% found this document useful (0 votes)
59 views4 pages

C Programming Theory Quiz - SOLUTION

Uploaded by

Harshit Jain
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 4

Computer Programming Theory (CSI101) Quiz1 [SESSION: 2023-24] Time: 45 Min.

Answer ALL questions, each carry One Mark, there may be multiple Answers, No Marks for partial Answers

Admission Number and Section:

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

4. What is the use of the for loop initialization expression?


A. To declare a loop counter variable. B. To set the initial value of the loop counter.
C. To define the number of iterations. D. All of the above.
5. What is the purpose of header files in C?
A. To store function definitions. B. To declare global variables.
C. To include predefined functions and constants. D. To organize code into modules.
6. What is the concept of pointers in C?
A. Variables that store memory addresses. B. Variables that can hold any data type.
C. Variables that can be modified dynamically. D. All of the above.

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

11. Which is a valid C expression?


A. int new_num = 10,000; B. int new_num = 100000; C. int new num = 100; D. int $new_num = 1000;
12. What are the elements present in the array of the following C code?

int array[6] = {5};

A. 5, 5, 5, 5, 5, 5 B. 5, 0, 0, 0, 0, 0 C. 6, 6, 6, 6, 6, 6 D. (garbage), (garbage), (garbage), (garbage), (garbage), 5


13. What is the output of the following C code?

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

14. What is the output of this C code?

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);}

A. Nothing B. Runtime error C. Varies D. Hello is printed infinite times


16. What will be the output of the following C code?

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?

void f(int a[][3]){


a[0][1] = 3;
int i = 0, j = 0;
for (i = 0; i < 2; i++)
for (j = 0; j < 3; j++)
printf("%d ", a[i][j]);}
void main(){
int a[2][3] = {0};
f(a);}

A. 0 3 0 0 0 0 B. (garbage) 3 (garbage) (garbage) (garbage) (garbage)


C. Compile time error D. All garbage values
19. What will this program print?

main() {
int i = 2; {
int i = 4, j = 5;
printf("%d %d", i, j);}
printf("%d %d", i, j); }

A. 4525 B. 2525 C. 4545 D. None of the above


20. How is the 5th element in an array accessed based on pointer notation?
A. *a + 5 B. *(a + 5) C. *(*a + 5) D. &(a + 5)
21. What is the appropriate implementation for finding the Greatest Common Divisor (GCD) of two numbers?
A. int gcd(int a, int b) while (b != 0) int temp = b; b = a % b; a = temp; return a;
B. int gcd(int a, int b) return a % b == 0 ? b : gcd(b, a % b);
C. int gcd(int a, int b) while (a != 0) int temp = a; a = b % a; b = temp; return b;
D. int gcd(int a, int b) return b % a == 0 ? a : gcd(b % a, a);
22. The following statement in ‘C’ declares
A. a function returning a pointer to an array of integers B. a function returning an array of pointers to integers
C. array of functions returning pointers to integers D. an illegal statement
23. Given that x = 7.5, j = -1.0, n = 1.0, m = 2.0 the value of − − x + j == x > n >= m is:
A. 0 B. 1 C. 2 D. 3

Computer Programming Quiz Page 2 of 4


24. C is ________ type of programming language.?
A. Object Oriented B. Procedural C. Bit level language D. Functional
25. Choose the right C statement.
A. int my_age = 10; B. int my,age = 10; C. int my age = 10; D. All are correct

26. The following function computes the maximum value contained in an integer. Fill in the blank:

array p[] of size n (n >= 1)


int max(int *p, int n){
int a=0, b=n-1;
while (-----------------){
if (p[a] <= p[b]){
a = a+1;}
else{
b = b-1;
}}
return p[a];}

A. p[a] < p[b] B. p[a] > p[b] C. a < b D. a > b


27. What is the output of the following code snippet?

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

29. What will be the output of the following code snippet?

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;}

A. 1 2 3 None B. 2 C. 2 3 None D. None


30. What will be the output of the following code snippet (Assume all header files are included)?

void solve() {
char s[] = "Hello";
printf("%s ", s);
char t[40];
strcpy(t, s);
printf("%s", t);}
int main() {
solve();
return 0;}

A. Hello Hello B. Hello C. Compilation Error D. None

31. What will be the output of the following program?

Computer Programming Quiz Page 3 of 4


int main(){
int a=72,b=072,c=0x72;
printf("a=%d b=%d c=%d",a,b,c);
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;}

A. m=120 B. m=0 C. Compile time error D. Runtime Error


33. What will be the output of the following program?

int main(){
int x, y =32;
char z= ’A’;
x= y + z;
printf("%c %c %c",x,x+1,x+2);
return 0;}

A. A B C B. a b c C. 97 98 99 D. Compile time Error


34. Which of the following is/are not operator(s) in C language?
A. & B. sizeof C. # D. @
35. Consider the following declaration of the variables: int x, A[5][6], *p=&A[0][0]; Which of the following is/are the
correct expression(s) to access A[3][5] and assign it to x?
A. x=*(p+23); B. x=*(p+28); C. x=*(*(A+6)+3); D. x=*(*(A+3)+5);
36. What will be the output of the following program?

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;}

A. 1 8 B. 1 1 C. 1 32 D. Compile time Error


37. State whether the statements are TRUE or FALSE?
(a) Function header and function declaration indicates the same in C language .
(b) In C, a function is NOT allowed to be defined within another function .
(c) During function calls, the function activation records are stored in Stack .
(d) C does not allow to declare pointer to a function .
38. What would be returned by the following function call?

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}};

A. 1440 B. 1444 C. 1448 D. 1452

Computer Programming Quiz Page 4 of 4

You might also like