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

Set-26 C MCQ

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

    #include<stdio.h>
    struct student
    {
    char *name;
    };
    struct student s[2];
    void main()
    {
    s[0].name = “alan”;
    s[1] = s[0];
    printf(“%s%s”, s[0].name, s[1].name);
    s[1].name = “turing”;
    printf(“%s%s”, s[0].name, s[1].name);
    }

    a) alan alan alan turing
    b) alan alan turing turing
    c) alan turing alan turing
    d) run time error

Answer : A


  1. Which of the following will stop the loop at the last node of a linked list in the following C code snippet?

    struct node
    {
    struct node *next;
    };

a) while (p != NULL)
{
p = p->next;
}

b) while (p->next != NULL)
{
p = p->next;
}

c) while (1)
{
p = p->next;
if (p == NULL)
break;
}

d) All of the mentioned

Answer : B


3.The purpose of the preprocessor directive #error is that __

a) It rectifies any error present in the code
b) It rectifies only the first error which occurs in the code
c) It causes the preprocessor to report a fatal error
d) It causes the preprocessor to ignore an error

Answer : C


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

#include<stdio.h>
define hello 10
main()
{
#ifdef hello
#undef hello
#define hello 100
#else
#define hello 200
#endif
printf(“%d”,hello);
}
a) Error
b) 10
c) 100
d) 200

Answer : C


  1. atoi() function is used for:

    a)convert ASCII character to integer value
    b)convert a character string to its equivalent integer value
    c)gets index value of character in an array
    d)converts an array of characters to array of equivalent integers

Answer : B


  1. What will happen if in a C program you assign a value to an array element whose subscript exceeds the size of array?

A. The element will be set to 0.
B. The compiler would report an error.
C. The program may crash if some important data gets overwritten.
D. The array size would appropriately grow

Answer : C


  1. What would be the time complexity to add a node at the end of singly linked list, if the pointer is initially pointing to the head of the list?

a) O(1)
b) O(n)
c) O(n*n)
d) None of these

Answer : B
C MCQ Set-26 Explanation


  1. The initial configuration of a queue is a, b, c, d, (‘a’ is in the front end). To get the configuration d, c, b, a, one needs a minimum of

A. 2 deletions and 3 additions

B. 3 deletion and 2 additions

C. 3 deletions and 3 additions

D. 3 deletions and 4 additions

Answer : C


  1. What will be the output of the program?

#include<stdio.h>
define MAN(x, y) ((x)>(y)) ? (x):(y);
int main()
{
int i=10, j=5, k=0;
k = MAN(++i, j++);
printf(“%d, %d, %d\n”, i, j, k);
return 0;
}
A. 12, 6, 12
B. 11, 5, 11
C. 11, 5, Garbage
D. 12, 6, Garbage

Answer: A
C MCQ Set-26 Explanation


  1. What will be the output of the program

#include<stdio.h>
define SQR(x)(x*x)
int main()
{
int a, b=3;
a = SQR(b+2);
printf(“%d\n”, a);
return 0;
}

A. 25
B. 11
C. Error
D. Garbage value

Answer: B


Spread the love

Leave a Comment

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