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

1. The function ____ obtains block of memory dynamically.
a) calloc
b) malloc
c) Both calloc & malloc
d) free

View Answer

Answer: c

2. void * malloc(size_t n) returns
a) Pointer to n bytes of uninitialized storage
b) NULL if the request can be satisfied
c) Nothing
d) None of the mentioned

View Answer

Answer: a

3. calloc() returns a storage that is initialized to.
a) Zero
b) Null
c) Nothing
d) One

View Answer

Answer: a

4. In function free(p), p is a
a) int
b) Pointer returned by malloc()
c) Pointer returned by calloc()
d) Pointer returned by malloc() & calloc()

View Answer

Answer: d

5. What is the output of this C code?

  1.     #include <stdio.h>
  2.     void main()
  3.     {
  4.         char *p = calloc(100, 1);
  5.         p = "welcome";
  6.         printf("%sn", p);
  7.     }

a) Segmentation fault
b) Garbage
c) Error
d) welcome

View Answer

Answer: d

6. Memory allocation using malloc() is done in?
a) Static area
b) Stack area
c) Heap area
d) Both Stack & Heap area

View Answer

Answer: c

7. Why do we write (int *) before malloc?
    int *ip = (int *)malloc(sizeof(int));
a) It is for the syntax correctness
b) It is for the type-casting
c) It is to inform malloc function about the data-type expected
d) None of the mentioned

View Answer

Answer: b

8. Which one is used during memory deallocation in C?
a) remove(p);
b) delete(p);
c) free(p);
d) terminate(p);

View Answer

Answer: c

Set 2

1. What is the output of this C code?

  1.     #include <stdio.h>
  2.     int main()
  3.     {
  4.         char *str = "hello, world";
  5.         char *str1 = "hello, world";
  6.         if (strcmp(str, str1))
  7.             printf("equal");
  8.         else
  9.             printf("unequal");
  10.     }

a) equal
b) unequal
c) Compilation error
d) Depends on the compiler

View Answer

Answer: b

2. What is the output of this C code?

  1.     #include <stdio.h>
  2.     int main()
  3.     {
  4.         char *str = "hello";
  5.         char str1[5];
  6.         strcpy(str, str1);
  7.         printf("%s", str1);
  8.     }

a) Compilation error
b) Undefined behaviour
c) hello, world
d) hello, wo 9

View Answer

Answer: d

3. What is the output of this C code?

  1.     #include <stdio.h>
  2.     #include <string.h>
  3.     int main()
  4.     {
  5.         char *str = "hello, world";
  6.         char str1[9];
  7.         strncpy(str1, str, 9);
  8.         printf("%s %d", str1, strlen(str1));
  9.     }

a) hello, world 11
b) hello, wor 9
c) Undefined behaviour
d) Compilation error

View Answer

Answer: c

4. What is the output of this C code?

  1.     #include <stdio.h>
  2.     int main()
  3.     {
  4.         char *str = "hello, worldn";
  5.         printf("%d", strlen(str));
  6.  
  7.     }

a) Compilation error
b) Undefined behaviour
c) 13
d) 11

View Answer

Answer: c

5. What is the output of this C code?

  1.     #include <stdio.h>
  2.     int main()
  3.     {
  4.         char str[11] = "hello";
  5.         char *str1 = "world";
  6.         strcat(str, str1);
  7.         printf("%s %d", str, str[10]);
  8.     }

a) helloworld 0
b) helloworld anyvalue
c) worldhello 0
d) Segmentation fault/code crash

View Answer

Answer: a

6. Strcat function adds null character
a) Only if there is space
b) Always
c) Depends on the standard
d) Depends on the compiler

View Answer

Answer: b

7. What is the output of this C code?

  1.     #include <stdio.h>
  2.     int main()
  3.     {
  4.         char str[10] = "hello";
  5.         char *str1 = "world";
  6.         strncat(str, str1, 9);
  7.         printf("%s", str);
  8.     }

a) helloworld
b) Undefined behaviour
c) helloworl
d) hellowor

View Answer

Answer: a

Set 3

1. What is the output of this C code?

  1.     #include <stdio.h>
  2.     typedef struct student
  3.     {
  4.         char *a;
  5.     }stu;
  6.     void main()
  7.     {
  8.         struct stu s;
  9.         s.a = "hi";
  10.         printf("%s", s.a);
  11.     }

a) Compile time error
b) Varies
c) hi
d) h

View Answer

Answer: a

2. What is the output of this C code?

  1.     #include <stdio.h>
  2.     typedef struct student
  3.     {
  4.         char *a;
  5.     }stu;
  6.     void main()
  7.     {
  8.         struct student s;
  9.         s.a = "hey";
  10.         printf("%s", s.a);
  11.     }

a) Compile time error
b) Varies
c) he
d) hey

View Answer

Answer: d

3. What is the output of this C code?

  1.     #include <stdio.h>
  2.     typedef int integer;
  3.     int main()
  4.     {
  5.         int i = 10, *ptr;
  6.         float f = 20;
  7.         integer j = i;
  8.         ptr = &j;
  9.         printf("%dn", *ptr);
  10.         return 0;
  11.     }

a) Compile time error
b) Undefined behaviour
c) Depends on the standard
d) 10

View Answer

Answer: d

4. What is the output of this C code?

  1.     #include <stdio.h>
  2.     int (*(x()))[2];
  3.     typedef int (*(*ptr)())[2] ptrfoo;
  4.     int main()
  5.     {
  6.         ptrfoo ptr1;
  7.         ptr1 = x;
  8.         ptr1();
  9.         return 0;
  10.     }
  11.     int (*(x()))[2]
  12.     {
  13.         int (*ary)[2] = malloc(sizeof*ary);
  14.         return &ary;
  15.     }

a) Compile time error
b) Nothing
c) Undefined behaviour
d) Depends on the standard

View Answer

Answer: a

5. What is the output of this C code?

  1.     #include <stdio.h>
  2.     int *(*(x()))[2];
  3.     typedef int **(*ptrfoo)())[2];
  4.     int main()
  5.     {
  6.         ptrfoo ptr1;
  7.         ptr1 = x;
  8.         ptr1();
  9.         return 0;
  10.     }
  11.     int *(*(x()))[2]
  12.     {
  13.         int (*ary)[2] = malloc(sizeof * ary);
  14.         return &ary;
  15.     }

a) Compile time error
b) Nothing
c) Undefined behaviour
d) Depends on the standard

View Answer

Answer: b

6. What is the output of this C code?

  1.     #include <stdio.h>
  2.     typedef struct p
  3.     {
  4.         int x, y;
  5.     };
  6.     int main()
  7.     {
  8.         p k1 = {1, 2};
  9.         printf("%dn", k1.x);
  10.     }

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

View Answer

Answer: a

7. What is the output of this C code?

  1.     #include <stdio.h>
  2.     typedef struct p
  3.     {
  4.         int x, y;
  5.     }k = {1, 2};
  6.     int main()
  7.     {
  8.         p k1 = k;
  9.         printf("%dn", k1.x);
  10.     }

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

View Answer

Answer: a

8. What is the output of this C code?

  1.     #include <stdio.h>
  2.     typedef struct p
  3.     {
  4.         int x, y;
  5.     }k;
  6.     int main()
  7.     {
  8.         struct p p = {1, 2};
  9.         k k1 = p;
  10.         printf("%dn", k1.x);
  11.     }

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

View Answer

Answer: b

Set 4

1. What is the output of this C code?

  1.     #include <stdio.h>
  2.     #include <stdarg.h>
  3.     void func(int, ...);
  4.     int main()
  5.     {
  6.         func(2, 3, 5, 7, 11, 13);
  7.         return 0;
  8.     }
  9.     void func(int n, ...)
  10.     {
  11.         int number, i = 0;
  12.         va_list start;
  13.         va_start(start, n);
  14.         while (i != 3)
  15.         {
  16.             number = va_arg(start, int);
  17.             i++;
  18.         }
  19.         printf("%d", number);
  20.     }

a) 3
b) 5
c) 7
d) 11

View Answer

Answer: c

2. Which of the following function with ellipsis are illegal?
a) void func(…);
b) void func(int, …);
c) void func(int, int, …);
d) none of the mentioned

View Answer

Answer: a

3. Which of the following data-types are promoted when used as a parameter for an ellipsis?
a) char
b) short
c) int
d) none of the mentioned

View Answer

Answer: a

4. Which header file includes a function for variable number of arguments?
a) stdlib.h
b) stdarg.h
c) ctype.h
d) both stdlib.h and stdarg.h

View Answer

Answer: b

5. Which of the following macro extracts an argument from the variable argument list (ie ellipsis)      and advance the pointer to the next argument?
a) va_list
b) va_arg
c) va_end
d) va_start

View Answer

Answer: b

6. The type va_list is used in an argument list
a) To declare a variable that will refer to each argument in turn;
b) For cleanup
c) To create a list
d) There is no such type

View Answer

Answer: a

7. The declaration … can
a) Appear anywhere in the function declaration
b) Only appear at the end of an argument list
c) Nothing
d) None of the mentioned

View Answer

Answer: b

8. Each call of va_arg
a) Returns one argument
b) Steps va_list variable to the next
c) Returns one argument & Steps va_list variable to the next
d) None of the mentioned

View Answer

Answer: c

Set 5

1. What is the output of this C code?

  1.     #include <stdio.h>
  2.     void main()
  3.     {
  4.         struct student
  5.         {
  6.             int no;
  7.             char name[20];
  8.         };
  9.         struct student s;
  10.         no = 8;
  11.         printf("%d", no);
  12.     }

a) Nothing
b) Compile time error
c) Junk
d) 8

View Answer

Answer: b

2. What is the output of this C code?

  1.     #include <stdio.h>
  2.     struct student
  3.     {
  4.         int no;
  5.         char name[20];
  6.     };
  7.     void main()
  8.     {
  9.         struct student s;
  10.         s.no = 8;
  11.         printf("hello");
  12.     }

a) Run time error
b) Nothing
c) hello
d) Varies

View Answer

Answer: c

3. What is the output of this C code?

  1.     #include <stdio.h>
  2.     struct student
  3.     {
  4.         int no = 5;
  5.         char name[20];
  6.     };
  7.     void main()
  8.     {
  9.         struct student s;
  10.         s.no = 8;
  11.         printf("hello");
  12.     }

a) Nothing
b) Compile time error
c) hello
d) Varies

View Answer

Answer: b

4. What is the output of this C code?

  1.     #include <stdio.h>
  2.     struct student
  3.     {
  4.         int no;
  5.         char name[20];
  6.     };
  7.     void main()
  8.     {
  9.         student s;
  10.         s.name = "hello";
  11.         printf("hello");
  12.     }

a) Nothing
b) hello
c) Compile time error
d) Varies

View Answer

Answer: c

5. What is the output of this C code?

  1.     #include <stdio.h>
  2.     void main()
  3.     {
  4.         struct student
  5.         {
  6.             int no;
  7.             char name[20];
  8.         };
  9.         struct student s;
  10.         s.no = 8;
  11.         printf("%s", s.name);
  12.     }

a) Nothing
b) Compile time error
c) Junk
d) 8

View Answer

Answer: c

6. What is the output of this C code?

  1.     #include <stdio.h>
  2.     struct student
  3.     {
  4.         int no;
  5.         char name[20];
  6.     };
  7.     struct student s;
  8.     void main()
  9.     {
  10.         s.no = 8;
  11.         printf("%s", s.name);
  12.     }

a) Nothing
b) Compile time error
c) Junk
d) 8

View Answer

Answer: a

7. What is the output of this C code?

  1.     #include <stdio.h>
  2.     int main()
  3.     {
  4.         int *((*x)())[2];
  5.         x();
  6.         printf("after xn");
  7.     }
  8.     int *((*x)())[2]
  9.     {
  10.         int **str;
  11.         str = (int*)malloc(sizeof(int)* 2);
  12.         return str;
  13.     }

a) Compile time error
b) Undefined behaviour
c) After x
d) None of the mentioned

View Answer

Answer: a

8. What is the output of this C code?

  1.     #include <stdio.h>
  2.     void (*(f)())(int, float);
  3.     void (*(*x)())(int, float) = f;
  4.     void ((*y)(int, float));
  5.     void foo(int i, float f);
  6.     int main()
  7.     {
  8.         y = x();
  9.         y(1, 2);
  10.     }
  11.     void (*(f)())(int, float)
  12.     {
  13.         return foo;
  14.     }
  15.     void foo(int i, float f)
  16.     {
  17.         printf("%d %fn", i, f);
  18.     }

a) 1 2.000000
b) 1 2
c) Compile time error
d) Segmentation fault/code crash

View Answer

Answer: a

9. What does this declaration say?
    int (*(*y)())[2];
a) y is pointer to the function which returns pointer to integer array
b) y is pointer to the function which returns array of pointers
c) y is function which returns function pointer which in turn returns pointer to integer array
d) y is function which returns array of integers

View Answer

Answer: a

10. What is the output of this C code?

  1.     #include <stdio.h>
  2.     void (*(f)())(int, float);
  3.     typedef void (*(*x)())(int, float);
  4.     void foo(int i, float f);
  5.     int main()
  6.     {
  7.         x = f;
  8.         x();
  9.     }
  10.     void (*(f)())(int, float)
  11.     {
  12.         return foo;
  13.     }
  14.     void foo(int i, float f)
  15.     {
  16.         printf("%d %fn", i, f);
  17.     }

a) Compile time error
b) Undefined behaviour
c) 1 2.000000
d) Nothing

View Answer

Answer: a

11. What is the output of this C code?

  1.     #include <stdio.h>
  2.     void (*(f)())(int, float);
  3.     typedef void (*(*x)())(int, float);
  4.     void foo(int i, float f);
  5.     int main()
  6.     {
  7.         x p = f;
  8.         p();
  9.     }
  10.     void (*(f)())(int, float)
  11.     {
  12.         return foo;
  13.     }
  14.     void foo(int i, float f)
  15.     {
  16.         printf("%d %fn", i, f);
  17.     }

a) Compile time error
b) Undefined behaviour
c) 1 2.000000
d) Nothing

View Answer

Answer: d

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