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. What is the output of this C code?

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

a) Compile time error
b) sizeof(int) + sizeof(char)
c) Depends on the compiler
d) sizeof(int)

View Answer

Answer: d

2. What is the output of this C code?

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

a) Compile time error
b) sizeof(int) + sizeof(char)
c) Depends on the compiler
d) sizeof(char)

View Answer

Answer: c

3. What is the output of this C code?

  1.     #include <stdio.h>
  2.     union p
  3.     {
  4.         int x;
  5.         char y;
  6.     };
  7.     int main()
  8.     {
  9.         union p p, b;
  10.         p.y = 60;
  11.         b.x = 12;
  12.         printf("%dn", p.y);
  13.     }

a) Compile time error
b) Depends on the compiler
c) 60
d) Undefined behaviour

View Answer

Answer: c

4. What is the output of this C code?

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

a) Compile time error
b) 97
c) a
d) 1

View Answer

Answer: d

5. What is the output of this C code?

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

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

View Answer

Answer: b

6. What is the output of this C code?

  1.     #include <stdio.h>
  2.     union p
  3.     {
  4.         int x;
  5.         float y;
  6.     };
  7.     int main()
  8.     {
  9.         union p p, b;
  10.         p.x = 10;
  11.         printf("%fn", p.y);
  12.     }

a) Compile time error
b) Implementation dependent
C) 10.000000
d) 0.000000

View Answer

Answer: b

7. Which of the following share a similarity in syntax?
     1. Union, 2. Structure, 3. Arrays and 4. Pointers
a) 3 and 4
b) 1 and 2
c) 1 and 3
d) 1, 3 and 4

View Answer

Answer: b

8. What is the output of this C code?

  1.     #include <stdio.h>
  2.     union utemp
  3.     {
  4.         int a;
  5.         double b;
  6.         char c;
  7.     }u;
  8.     int main()
  9.     {
  10.         u.c = 'A';
  11.         u.a = 1;
  12.         printf("%d", sizeof(u));
  13.     }

    The output will be: (Assuming size of char = 1, int = 4, double = 8)
a) 1
b) 4
c) 8
d) 13

View Answer

Answer: c

Set 2

1. What is the output of this C code if there is no error in stream fp?

  1.     #include <stdio.h>
  2.     int main()
  3.     {
  4.         FILE *fp;
  5.         fp = fopen("newfile", "w");
  6.         printf("%dn", ferror(fp));
  7.         return 0;
  8.     }

a) Compilation error
b) 0
c) 1
d) Any nonzero value

View Answer

Answer: b

2. Within main, return expr statement is equivalent to.
a) abort(expr)
b) exit(expr)
c) ferror(expr)
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.         FILE *fp;
  5.         char c;
  6.         int n = 0;
  7.         fp = fopen("newfile1.txt", "r");
  8.         while (!feof(fp))
  9.         {
  10.             c = getc(fp);
  11.             putc(c, stdout);
  12.         }
  13.     }

a) Compilation error
b) Prints to the screen content of newfile1.txt completely
c) Prints to the screen some contents of newfile1.txt
d) None of the mentioned

View Answer

Answer: d

4. What is the output of this C code?

  1.     #include <stdio.h>
  2.     int main()
  3.     {
  4.         FILE *fp = stdout;
  5.         stderr = fp;
  6.         fprintf(stderr, "%s", "hello");
  7.     }

a) Compilation error
b) hello
c) Undefined behaviour
d) Depends on the standard

View Answer

Answer: b

5. What is the output of this C code?

  1.     #include <stdio.h>
  2.     int main()
  3.     {
  4.         char buf[12];
  5.         stderr = stdin;
  6.         fscanf(stderr, "%s", buf);
  7.         printf("%sn", buf);
  8.     }

a) Compilation error
b) Undefined behaviour
c) Whatever user types
d) None of the mentioned

View Answer

Answer: c

6. stderr is similar to?
a) stdin
b) stdout
c) Both stdout and stdin
d) None of the mentioned

View Answer

Answer: a

7. What happens when we use
    fprintf(stderr, “error: could not open filen”);
a) The diagnostic output is directly displayed in the output.
b) The diagnostic output is pipelined to the output file.
c) The line which caused error is compiled again.
d) The program is immediately aborted.

View Answer

Answer: a

8. Which of the following function can be used to terminate the main function from another function safely?
a) return(expr);
b) exit(expr);
c) abort();
d) Both exit(expr); and abort();

View Answer

Answer: b

Set 3

1. What is the correct syntax to initialize bit-fields in an structure?

a) struct temp
    {
        unsigned int a : 1;
    }s;
b) struct temp
    {
        unsigned int a = 1;
    }s;
c) struct temp
    {
        unsigned float a : 1;
    }s;
d) None of the mentioned

View Answer

Answer: a

2. Which of the following data types are accepted while declaring bit-fields?
a) char
b) float
c) double
d) none of the mentioned

View Answer

Answer: a

3. Which of the following reduces the size of a structure?
a) union
b) bit-fields
c) malloc
d) none of the mentioned

View Answer

Answer: b

4. For what minimum value of x in a 32-bit Linux OS would make the size of s equal to 8 bytes?

  1.     struct temp
  2.     {
  3.         int a : 13;
  4.         int b : 8;
  5.         int c : x;
  6.     }s;

a) 4
b) 8
c) 12
d) 32

View Answer

Answer: c

5. Calculate the % of memory saved when bit-fields are used for the following structure.?
    (Assuming size of int = 4, calculate the % using the memory that would be occupied without     bit-fields)

  1.     struct temp
  2.     {
  3.         int a : 1;
  4.         int b : 2;
  5.         int c : 4;
  6.         int d : 4;
  7.     }s;

a) 25%
b) 33.3%
c) 50%
d) 75%

View Answer

Answer: d

6. In the declaration of bit-fields,

    struct-declarator:
    declarator
    type-specifier declarator opt : constant-expression
    The constant-expression specifies

a) The width of the field in bits.
b) Nothing
c) The width of the field in bytes.
d) Error

View Answer

Answer: a

7. In the declaration of bit-fields,

    struct-declarator:
    declarator
    type-specifier declarator opt : constant-expression
    The constant-expression must be

a) Any type
b) Nothing
c) Integer value
d) Nonnegative integer value

View Answer

Answer: d

8. Which of the following is not allowed?
a) Arrays of bit fields
b) Pointers to bit fields
c) Functions returning bit fields
d) None of the mentioned

View Answer

Answer: d

9. Bit fields can only be declared as part of a structure.
a) false
b) true
c) Nothing
d) Varies

View Answer

Answer: b

10. The following declarations in order are

    short a : 17;
    int long y : 33;

a) Legal, legal
b) Legal, illegal
c) Illegal, illegal
d) Illegal, legal

View Answer

Answer: c

Set 4

1. ungetc can be used only with getc.
a) true
b) false
c) depends on the standard
d) depends on the platform

View Answer

Answer: b

2. Which character of pushback is guaranteed per file?
a) True
b) False
c) Depends on the compiler
d) Depends on the platform

View Answer

Answer: a

3. What is the output of this C code?

  1.     #include <stdio.h>
  2.     int main()
  3.     {
  4.         int n;
  5.         scanf("%d", &n);
  6.         ungetc(n, stdin);
  7.         scanf("%d", &n);
  8.         printf("%dn", n);
  9.         return 0;
  10.     }

a) Compile time error
b) Whatever is typed by the user first time
c) Whatever is typed by the user second time
d) Undefined behaviour

View Answer

Answer: b

4. What is the output of this C code?

  1.     #include <stdio.h>
  2.     int main()
  3.     {
  4.         char n[20];
  5.         fgets(n, 19, stdin);
  6.         ungetc(n[0], stdin);
  7.         scanf("%s", n);
  8.         printf("%sn", n);
  9.         return 0;
  10.     }

a) Compile time error
b) Whatever string user types second time
c) Whatever string user types first time
d) first character of whatever user types first time and whatever user types second time

View Answer

Answer: d

5. What is the output of this code considering user typed jkl?

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

a) jkl
b) kl
c) Undefined behaviour
d) jk

View Answer

Answer: a

6. How many characters for pushback is guaranteed per file while using
    ungetc(c, fp);
a) Only 1 character
b) Characters within 1 word
c) Characters within 1st new-line
d) All characters upto NULL character

View Answer

Answer: a

7. Which of the following is the correct syntax for calling function ungetc?
    Assume int c and FILE *fp
a) ungetc(c,*fp);
b) ungetc(c, fp);
c) ungetc(fp, c);
d) ungetc(*fp,c);

View Answer

Answer: b

8. ungetc is used
a) to get a char
b) to get an int
c) to push a character back to file
d) nothing

View Answer

Answer: c

Set 5

1. The first and second arguments of fopen are
a) A character string containing the name of the file & the second argument is the mode
b) A character string containing the name of the user & the second argument is the mode
c) A character string containing file poniter & the second argument is the mode
d) None of the mentioned

View Answer

Answer: a

2. For binary files, a ___ must be appended to the mode string.
a) Nothing
b) “b”
c) “binary”
d) “01”

View Answer

Answer: b

3. If there is any error while opening a file, fopen will return
a) Nothing
b) EOF
c) NULL
d) Depends on compiler

View Answer

Answer: c

4. Which is true about getc.getc returns?
a) The next character from the stream is not referred by file pointer
b) EOF for end of file or error
c) Nothing
d) None of the mentioned

View Answer

Answer: b

5. When a C program is started, O.S environment is responsible for opening file and providing     pointer for that file?
a) Standard input
b) Standard output
c) Standard error
d) All of the menitoned

View Answer

Answer: d

6. FILE is of type ______
a) int type
b) char * type
c) struct type
d) None of the mentioned

View Answer

Answer: c

7. What is the meant by ‘a’ in the following operation?
    fp = fopen(“Random.txt”, “a”);
a) Attach
b) Append
c) Apprehend
d) Add

View Answer

Answer: b

8. Which of the following mode argument is used to truncate?
a) a
b) f
c) w
d) t

View Answer

Answer: c

9. Which type of files can’t be opened using fopen()?
a) .txt
b) .bin
c) .c
d) none of the mentioned

View Answer

Answer: d