Generic selectors
Exact matches only
Search in title
Search in content
Search in posts
Search in pages
Filter by Categories
nmims post
Objective Type Set
Online MCQ Assignment
Question Solution
Solved Question
Uncategorized

Multiple choice question for engineering

Set 1

Here is a listing of advanced C interview questions on “Line Input & Output” along with answers, explanations and/or solutions:

1. The syntax of fgets is char *fgets(char *line, int maxline, FILE *fp).which is true for     fgets.fgets
a) returns line on success
b) On end of file or error it returns NULL
c) Nothing
d) Both returns line on success & On end of file or error it returns NULL

View Answer

Answer: d

2. fputs function writes a string to a file that only ends with a newline.
a) true
b) false
c) Depends on the standard
d) Depends on the compiler

View Answer

Answer: b

3. What is the output of this C code?

  1.     #include <stdio.h>
  2.     #include <string.h>
  3.     int main()
  4.     {
  5.         char line[3];
  6.         fgets(line, 3, stdin);
  7.         printf("%dn", strlen(line));
  8.         return 0;
  9.     }

a) 3
b) 1
c) Any length since line did not end with null character
d) Depends on the standard

View Answer

Answer: b

4. What is the output of this C code?

  1.     #include <stdio.h>
  2.     #include <string.h>
  3.     int main()
  4.     {
  5.         char line[3];
  6.         FILE *fp;
  7.         fp = fopen("newfile.txt", "r");
  8.         while (fgets(line, 3, fp))
  9.         fputs(line, stdout);
  10.         return 0;
  11.     }

a) Compilation error
b) Infinite loop
c) Segmentation fault
d) No.of lines present in file newfile

View Answer

Answer: c

5. What is the output of this C code if 2 character is typed by the user?

  1.     #include <stdio.h>
  2.     #include <string.h>
  3.     int main()
  4.     {
  5.         char line[3];
  6.         fgets(line, 3, stdin);
  7.         printf("%dn", line[2]);
  8.         return 0;
  9.     }

a) Compilation error
b) Undefined behaviour
c) 0
d) 10(ascii value of newline character)

View Answer

Answer: c

6. fputs adds newline character
a) True
b) False
c) Depends on the standard
d) Undefined behaviour

View Answer

Answer: b

7. puts function adds newline character
a) True
b) False
c) Depends on the standard
d) Undefined behaviour

View Answer

Answer: a

8. gets function checks overflow run
a) True
b) False
c) Depends on the standard
d) Depends on the compiler

View Answer

Answer: b

9. puts does the following when it writes to stdout
a) Deletes everything
b) Adds ‘t’ to the line written
c) Deletes the terminating ‘n’
d) Adds ‘n’ to the line written

View Answer

Answer: d

Set 2

Here is a listing of basic C questions on “Scope of a Variable” along with answers, explanations and/or solutions:

1. The sequence of allocation and deletion of variables for the following code is.

  1.     #include <stdio.h>
  2.     int main()
  3.     {
  4.         int a;
  5.         {
  6.             int b;
  7.         }
  8.     }

a) a->b, a->b
b) a->b, b->a
c) b->a, a->b
d) b->a, b->a

View Answer

Answer: b

2. Array sizes are optional during array declaration by using ______ keyword.
a) auto
b) static
c) extern
d) register

View Answer

Answer: c

3. What is the output of this C code?

  1.     #include <stdio.h>
  2.     void main()
  3.     {
  4.         int x = 3;
  5.         {
  6.             x = 4;
  7.             printf("%d", x);
  8.         }
  9.     }

a) 4
b) 3
c) 0
d) Undefined

View Answer

Answer: a

4. What is the output of this C code?

  1.     #include <stdio.h>
  2.     int x = 5;
  3.     void main()
  4.     {
  5.         int x = 3;
  6.         m();
  7.         printf("%d", x);
  8.     }
  9.     void m()
  10.     {
  11.         x = 8;
  12.         n();
  13.     }
  14.     void n()
  15.     {
  16.         printf("%d", x);
  17.     }

a) 8 3
b) 3 8
c) 8 5
d) 5 3

View Answer

Answer: a

5. What is the output of this C code?

  1.     #include <stdio.h>
  2.     int x;
  3.     void main()
  4.     {
  5.         m();
  6.         printf("%d", x);
  7.     }
  8.     void m()
  9.     {
  10.         x = 4;
  11.     }

a) 0
b) 4
c) Compile time error
d) Undefined

View Answer

Answer: b

6. What is the output of this C code?

  1.     #include <stdio.h>
  2.     static int x = 5;
  3.     void main()
  4.     {
  5.         int x = 9;
  6.         {
  7.             x = 4;
  8.         }
  9.         printf("%d", x);
  10.     }

a) 9
b) 5
c) 4
d) 0

View Answer

Answer: c

7. What is the output of this C code?

  1.     #include <stdio.h>
  2.     void main()
  3.     {
  4.         {
  5.             int x = 8;
  6.         }
  7.         printf("%d", x);
  8.     }

a) 8
b) 0
c) Undefined
d) Compile time error

View Answer

Answer: d

Set 3

1. What is the output of this C code?

  1.     #include <stdio.h>
  2.     #include <stdlib.h>
  3.     int main()
  4.     {
  5.         printf("%dn", rand() % 1000);
  6.         return 0;
  7.     }

a) Compile time error
b) An integer between 0-1000
c) An integer between 0-999 including 0 and 999
d) An integer between 0-1000 including 1000

View Answer

Answer: c

2. What is the output of this C code?

  1.     #include <stdio.h>
  2.     #include <stdlib.h>
  3.     int main()
  4.     {
  5.         srand(9000);
  6.         printf("%dn", rand());
  7.         return 0;
  8.     }

a) Compile time error
b) An integer in the range 0 to RAND_MAX
c) A double in the range 0 to 1
d) A float in the range 0 to 1

View Answer

Answer: b

3. What is the output of this C code?

  1.     #include <stdio.h>
  2.     int main()
  3.     {
  4.         printf("%dn", srand(9000));
  5.         return 0;
  6.     }

a) Compile time error
b) An integer in the range 0 to 9000
c) A float in the range 0 to 1
d) A double in the range 0 to 9000

View Answer

Answer: a

4. What is the output of this C code?

  1.     #include <stdio.h>
  2.     int main()
  3.     {
  4.         srand(time(NULL));
  5.         printf("%dn", rand());
  6.         return 0;
  7.     }

a) Compile time error
b) An integer in the range 0 to RAND_MAX
c) A double in the range 0 to 1
d) A float in the range 0 to 1

View Answer

Answer: b

5. In the below program everytime program is run different numbers are generated.

  1.     #include <stdio.h>
  2.     #include <stdlib.h>
  3.     int main()
  4.     {
  5.         printf("%dn", rand());
  6.         return 0;
  7.     }

a) True
b) False
c) Depends on the platform
d) Depends on the compiler

View Answer

Answer: b

6. In the below program everytime program is run different numbers are generated.

  1.     #include <stdio.h>
  2.     int main()
  3.     {
  4.         srand(time(NULL));
  5.         printf("%dn", rand());
  6.         return 0;
  7.     }

a) True
b) False
c) Depends on the platform
d) Depends on the compiler

View Answer

Answer: a

7. Which of these is a correct way to generate numbers between 0 to 1(inclusive) randomly?
a) rand() / RAND_MAX
b) rand() % 2
c) rand(0, 1)
d) none of the mentioned

View Answer

Answer: a

Set 4

1. What is the output of this C code?

  1.     #include <stdio.h>
  2.     int main()
  3.     {
  4.         register int i = 10;
  5.         int *p = &i;
  6.         *p = 11;
  7.         printf("%d %dn", i, *p);
  8.     }

a) Depends on whether i is actually stored in machine register
b) 10 10
c) 11 11
d) Compile time error

View Answer

Answer: d

2. register keyword mandates compiler to place it in machine register.
a) true
b) false
c) Depends on the standard
d) None of the mentioned

View Answer

Answer: b

3. What is the output of this C code?

  1.     #include <stdio.h>
  2.     int main()
  3.     {
  4.         register static int i = 10;
  5.         i = 11;
  6.         printf("%dn", i);
  7.     }

a) 10
b) Compile time error
c) Undefined behaviour
d) 11

View Answer

Answer: b

4. What is the output of this C code?

  1.     #include <stdio.h>
  2.     int main()
  3.     {
  4.         register auto int i = 10;
  5.         i = 11;
  6.         printf("%dn", i);
  7.     }

a) 10
b) Compile time error
c) Undefined behaviour
d) 11

View Answer

Answer: b

5. What is the output of this C code?

  1.     #include <stdio.h>
  2.     int main()
  3.     {
  4.         register const int i = 10;
  5.         i = 11;
  6.         printf("%dn", i);
  7.     }

a) 10
b) Compile time error
c) Undefined behaviour
d) 11

View Answer

Answer: b

6. Register storage class can be specified to global variables
a) true
b) false
c) Depends on the compiler
d) Depends on the standard

View Answer

Answer: b

7. Which among the following is wrong for “register int a;” ?
a) Compiler generally ignores the request.
b) You cannot take the address of this variable
c) Access time to a is critical
d) None of the mentioned

View Answer

Answer: d

8. What is the output of this C code?

  1.     #include <stdio.h>
  2.     void main()
  3.     {
  4.         register int x = 5;
  5.         m();
  6.         printf("x is %d", x);
  7.     }
  8.     void m()
  9.     {
  10.         x++;
  11.     }

a) 6
b) 5
c) Junk value
d) Compile time error

View Answer

Answer: d

Set 5

1. What is the output of this C code?

  1.     #include <stdio.h>
  2.     typedef struct p *q;
  3.     int main()
  4.     {
  5.         struct p
  6.         {
  7.             int x;
  8.             char y;
  9.             q ptr;
  10.         };
  11.         struct p p = {1, 2, &p};
  12.         printf("%dn", p.ptr->x);
  13.         return 0;
  14.     }

a) Compile time error
b) 1
c) Depends on the compiler
d) None of the mentioned

View Answer

Answer: a

2. What is the output of this C code?

  1.     #include <stdio.h>
  2.     int main()
  3.     {
  4.         typedef struct p *q;
  5.         struct p
  6.         {
  7.             int x;
  8.             char y;
  9.             q ptr;
  10.         };
  11.         struct p p = {1, 2, &p};
  12.         printf("%dn", p.ptr->x);
  13.         return 0;
  14.     }

a) Compile time error
b) 1
c) Depends on the compiler
d) Depends on the standard

View Answer

Answer: b

3. What is the output of this C code?

  1.     #include <stdio.h>
  2.     typedef struct p *q;
  3.     struct p
  4.     {
  5.         int x;
  6.         char y;
  7.         q ptr;
  8.     };
  9.     int main()
  10.     {
  11.         struct p p = {1, 2, &p};
  12.         printf("%dn", p.ptr->ptr->x);
  13.         return 0;
  14.     }

a) Compile time error
b) Segmenation fault
c) Undefined behaviour
d) 1

View Answer

Answer: d

4. The number of distinct nodes the following struct declaration can point to is.

  1.     struct node
  2.     {
  3.         struct node *left;
  4.         struct node *centre;
  5.         struct node *right;
  6.     };

a) 1
b) 2
c) 3
d) All of the mentioned

View Answer

Answer: d

5. Which of the following is not possible?
a) A structure variable pointing to itself
b) A structure variable pointing to another structure variable of same type
c) 2 different type of structure variable pointing at each other
d) None of the mentioned

View Answer

Answer: d

6. Which of the following techinique is faster for travelling in binary trees?
a) Iteration
b) Recursion
c) Both Iteration and Recursion
d) Depends from compiler to compiler

View Answer

Answer: b

7. For the following declaration of structure, which of the following will stop the loop at the last node of a linked list?

  1.     struct node
  2.     {
  3.         struct node *next;
  4.     };
  1. a) while (p != NULL)
  2.     {
  3.         p = p->next;
  4.     }
  5. b) while (p->next != NULL)
  6.     {
  7.         p = p->next;
  8.     }
  9. c) while (1)
  10.     {
  11.         p = p->next;
  12.         if (p == NULL)
  13.             break;
  14.     }
  15. d) All of the mentioned

View Answer

Answer: b
.woocommerce-message { background-color: #98C391 !important; }