C MCQ Set-23 : Multiple Choice Questions in C Set-23

Set-26 C MCQ

1.Which of the following option is correct?

P1:
int main()
{
int (ptr)(int ) = fun; (ptr)(3);
return 0;
}

int fun(int n)
{
for(;n > 0; n–)
printf(“CQuiz “);
return 0;
}

P2:
int main()
{
void demo();
void (fun)(); fun = demo; (fun)();
fun();
return 0;
}

void demo()
{
printf(“CQuiz “);
}

(A) P1 printed “CQuiz CQuiz” and P2 printed “CsQuiz CQuiz”
(B) P1 printed “CQuiz CQuiz” and P2 gives compiler error
(C) P1 gives compiler error and P2 printed “CQuiz CQuiz”
(D) None of the above

Answer: (C)


2.In the context of the following printf() in C, pick the best statement.

i) printf(“%d”,8);
ii) printf(“%d”,090);
iii) printf(“%d”,00200);
iv) printf(“%d”,0007000);

A) Only i) would compile. And it will print 8.
(B) Both i) and ii) would compile. i) will print 8 while ii) will print 90
(C) All i), ii), iii) and iv) would compile successfully and they will print 8, 90, 200 & 7000 respectively.
(D) Only i), iii) and iv) would compile successfully. They will print 8, 128 and 3584 respectively.

Answer: (D)


  1. What’s going to happen when we compile and run the following C program snippet?

#include<stdio.h>
int main()
{
int a = 10;
int b = 15;

printf(“=%d”,(a+1),(b=a+2));
printf(” %d=”,b);

return 0;
}

(A) =11 15=
(B) =11 12=
(C) Compiler Error due to (b=a+2) in the first printf().
(D) No compile error but output would be =11 X= where X would depend on compiler implementation.

Answer: (B)


  1. Which of the following functions from “stdio.h” can be used in place of printf()?

(A) fputs() with FILE stream as stdout.
(B) fprintf() with FILE stream as stdout.
(C) fwrite() with FILE stream as stdout.
(D) All of the above three – a, b and c.
(E) In “stdio.h”, there’s no other equivalent function of printf().

Answer: (B)
C MCQ Set-23 Explanation


  1. What’s going to happen when we compile and run the following C program?

#include<stdio.h>
int main()
{
int j = 0;
for ( ; j < 10 ; )
{
if (j < 10)
printf(“Programming”, j++);
else
continue;
printf(“Quiz”);
}
return 0;
}

(A) Compile Error due to use of continue in for loop.
(B) No compile error but it will run into infinite loop printing “Programming”.
(C) No compile error and it’ll print “ProgrammingQuiz” 10 times followed by Quiz once.
(D) No compile error and it’ll print “ProgrammingQuiz” 10 times.

Answer: (D)


  1. What would happen when we compile and run this program?

#include<stdio.h>
int main()
{
int i=3;
goto LOOP;
for (i = 1 ; i <= 10 ; i++)
{
if(i%5==0)
break;
LOOP:
printf(“CQuiz\n”);
}
return 0;
}

(A) No compile error and it will print CQuiz 4 times because goto label LOOP wouldn’t come in effect.
(B) No compile error and it’ll print CQuiz 2 times
(C) Compile Error because any goto label isn’t allowed in for loop in C.
(D) No compile error and it will not print anything.

Answer: B
C MCQ Set-23 Explanation


  1. What does the following function do for a given Linked List with first node as head?

void fun1(struct node* head)
{
if(head == NULL)
return;

fun1(head->next);
printf(“%d “, head->data);
}
(A) Prints all nodes of linked lists
(B) Prints all nodes of linked list in reverse order
(C) Prints alternate nodes of Linked List
(D) Prints alternate nodes in reverse order

Answer: (B)
C MCQ Set-23 Explanation


  1. Following is C like pseudo code of a function that takes a number as an argument, and uses a stack S to do processing.

    void fun(int n)
    {
    Stack S; // Say it creates an empty stack S
    while (n > 0)
    {
    // This line pushes the value of n%2 to stack S
    push(&S, n%2); n = n/2;
    } // Run while Stack S is not empty
    while (!isEmpty(&S))
    printf(“%d “, pop(&S)); // pop an element from S and print it
    }

    What does the above function do in general?
    (A) Prints binary representation of n in reverse order
    (B) Prints binary representation of n
    (C) Prints the value of Logn
    (D) Prints the value of Logn in reverse order

Answer: (B)


  1. Find the output:

#include<stdlib.h>
#include<stdio.h>
enum {false, true};
int main()
{
int i = 1;
do
{
printf(“%d\n”, i);
i++;
if (i < 15)
continue;
} while (false);

getchar();
return 0;
}

A) 1
B) 0
C) Compilation Error
D) None of these

Answer: A


  1. What is the output of the program?

    #include‹stdio.h›
    int main()
    {
    struct site
    {
    char name[] = “Abdul Kalaam”;
    int no_of_pages = 200;
    };
    struct site *ptr;
    printf(“%d “, ptr->no_of_pages);
    printf(“%s”, ptr->name);
    getchar();
    return 0;
    }

(A) 200 Abdul Kalaam
(B) 200
(C) Runtime Error
(D) Compiler Error

Answer: (D)


Spread the love

Leave a Comment

Your email address will not be published. Required fields are marked *