250+ TOP MCQs on Non-Local Jumps and Answers

C Multiple Choice Questions & Answers on “Non-Local Jumps – 2”.

1. The header file setjmp.h is used to __________
a) set location specific information
b) control low-level calls and returns to and from functions
c) handle signals reported during a program’s execution
d) manipulate strings (character arrays)
Answer: b
Clarification: The header file setjmp.h is used to control low-level calls and returns to and from functions.

2. The void longjmp( jmp-buf env, int val) function causes setjmp() macro to return _______ value; if val is 0.
a) zero
b) one
c) null
d) no return
Answer: b
Clarification: The longjmp() function cannot cause the setjmp() to return value zero,if the variable val is zero. It always return one when the value of val is 0.

3. Which is the true statement with respect to the function longjmp()?
a) the function where setjmp() was called has terminated, then the results are undefined
b) the function where setjmp() was called has terminated, then the results are defined
c) the function where jmp_buf was called has terminated, then the results are undefined
d) the function where jmp_buf was called has terminated, then the results are defined
Answer: a
Clarification: The longjmp() function restores the environment saved by the most recent invocation of the set jmp macro in the same invocation of the program, with the corresponding jmp buf argument. The behavior is undefined, if there has been no such invocation, or if the function containing the invocation of the setjmp() macro has terminated execution in the interim.

4. Which of the given statement is not true with respect to void longjmp( jmp-buf env, int val)?
a) The variable value cannot be zero
b) env is the object containing information to restore the environment at the jmp_buf’s calling point
c) This function does not return any value
d) This function restores the environment saved by the most recent call to setjmp() macro
Answer: b
Clarification: In the function void longjmp( jmp-buf env, int val), env is the object containing information to restore the environment at the setjmp’s calling point.

5. What is the function of the given longjump(jmp_buf buf, i)?
a) go back to place buf is pointing to and return i
b) go back to place buf is pointing to and return 0
c) uses buf to remember current position and returns 0
d) uses buf to remember current position and returns i
Answer: a
Clarification: In the given function longjmp(jmp_buf buf,i), it goes back to place buf is pointing to and return i.setjmp(jmp_buf buf) uses buf to remember current position to and return 0.

6. How many times does the function longjmp() returns?
a) once
b) twice
c) thrice
d) never
Answer: d
Clarification: longjmp() function defined under setjmp.h header file does not return any value.

7. A less common use of setjmp.h is to create syntax similar to ____________
a) errno
b) variable arguments
c) coroutines
d) retval
Answer: c
Clarification: setjmp.h is sometime is used to create syntax similar to coroutines. Coroutines are computer program components.

8. What will the following C statement do?

#include < setjmp.h >
int setjmp(jmp_buf env);

a) save the current state of the registers into env
b) resets the registers to the values saved in env
c) provides a definition for env structure
d) accept variable(env) argument lists to be written
Answer: a
Clarification: The given statement is used to save the current state of the registers into env. The state of the program is dependent on the contents of its memory(code, stack, globals and heap) and the contents of its registers.

9. What are the contents of the register?
a) sp, fp only
b) sp only
c) fp, pc only
d) sp, fp, pc
Answer: d
Clarification: The contents of the registers includes sp, fp and cp. sp, fp and pc stands for stack pointer, frame pointer, and program counter.

10. setjmp takes a jmp_buf type and different other type variables as input.
a) true
b) false
Answer: b
Clarification: setjmp takes jmp_buf type variable as the only input.

contest

250+ TOP MCQs on Endianness and Answers

C Multiple Choice Questions & Answers (MCQs) on “Endianness”.

1. A machine in which the least significant byte is stored in the smallest address is __________
a) Big endian machine
b) Bi-endian machine
c) Binary bit machine
d) Little endian machine
Answer: d
Clarification: In little endian machines, last byte of binary representation (least significant byte) of a multi byte data type is stored first, whereas in big endian method, the first byte of binary representation of a multi byte data type is stored first.

2. If the output of the following C code is “Big endian”, then what will be the value of *a is?

#include 
int main()
{
   unsigned int i = 1;
   char *a = (char*)&i;
   if (*a)
       printf("Little endian");
   else
       printf("Big endian");
   getchar();
   return 0;
}

a) -1
b) 0
c) 1
d) 2
Answer: b
Clarification: In the code shown above, a character pointer ‘a’ points to an integer ‘i’. Since the size of the character is 1 byte, when the character pointer is de-referenced, it contains 1 integer byte. If the machine is a little endian machine then the value of *a will be 1, since the last byte is stored first. If the machine is big endian, the value of *a will be 0.

3. It is possible for a processor to support both little and big endian methods.
a) True
b) False
Answer: a
Clarification: It is possible for a processor to support both little and big endian methods. Such machines are known as bi-endian machines.

4. The standard byte order for networks is ____________
a) Bit-Binary
b) Little endian
c) Big endian
d) Bi-endian
Answer: c
Clarification: The standard byte order (network byte order) for networks is big endian. Before transferring data on a network, data is converted to big endian.

5. Which of the following is not an example of big endian machines?
a) Power PC
b) Motorola 68K
c) SPARC processors
d) ARM processors
Answer: d
Clarification: ARM processor is an example of little endian machine. Current generation ARM processor is an example of bi-endian machine. Power PC, Motorola 68K and SPARC are examples of big endian mahines.

6. Suppose we transfer a file written on a little endian machine to a big endian machine and there is no transformation from little endian to big endian, then what happens?
a) The big endian machine throws an error when it receives the file
b) The big endian machine reads the file in the reverse order
c) The big endian machine does not read the file
d) The big endian machine reads the file in the normal order
Answer: b
Clarification: If there is no transformation from little endian to big endian on transfer of a file from a little endian machine to a big endian machine, the big endian machine reads the file in reverse order.

7. File formats which have _________ as a basic unit are independent of endianness.
a) 1 byte
b) 2 bytes
c) 3 bytes
d) 4 bytes
Answer: a
Clarification: File formats which have 1 byte as the basic unit are not endianness dependent. Eg: ASCII files. Other file formats have fixed endianness formats.

8. If the code shown below is executed on a little endian machine, then what will be the output of the following C code?

#include
main()
{
    int y=1;
    printf("%d", (*(char*)&y));
}

a) 1
b) 1000
c) 9999
d) 0
Answer: a
Clarification: The output of the above code will be one when it is run on a little endian machine. This is because a little endian machine stores the least significant byte in the smallest address.

9. If the data “ABCD” is to be stored in a little endian machine, it will be stored as _________
a) ABCD
b) DCBA
c) CDAB
d) BCDA
Answer: b
Clarification: In a little endian machine, the least significant byte (right most) is stored in the smallest address. Hence the data “ABCD” will be stored in the form of “DCBA”.

10. The sequential order used to interpret a range of bytes in the memory of a computer is known as _________
a) Ordering
b) Sequencing
c) Endianness
d) Byte prediction
Answer: c
Clarification: Endianness is the sequential order used to interpret a range of bytes in the memory of a system.

250+ TOP MCQs on Increment and Decrement Operators and Answers

online C test on “Increment and Decrement Operators”. One shall practice these test questions to improve their C programming skills needed for various interviews (campus interviews, walkin interviews, company interviews), placements, entrance exams and other competitive exams. These questions can be attempted by anyone focusing on learning C Programming language. They can be a beginner, fresher, engineering graduate or an experienced IT professional. Our C online test questions come with detailed explanation of the answers which helps in better understanding of C concepts.

Here is a listing of online C test questions on “Increment and Decrement Operators” along with answers, explanations and/or solutions:

1. What is the difference between the following 2 codes?

  1.     #include  //Program 1
  2.     int main()
  3.     {
  4.         int d, a = 1, b = 2;
  5.         d =  a++ + ++b;
  6.         printf("%d %d %d", d, a, b);
  7.     }
  1.     #include  //Program 2
  2.     int main()
  3.     {
  4.         int d, a = 1, b = 2;
  5.         d =  a++ +++b;
  6.         printf("%d %d %d", d, a, b);
  7.     }

a) No difference as space doesn’t make any difference, values of a, b, d are same in both the case
b) Space does make a difference, values of a, b, d are different
c) Program 1 has syntax error, program 2 is not
d) Program 2 has syntax error, program 1 is not
Answer: d
Clarification: None.

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

  1.     #include 
  2.     int main()
  3.     {
  4.         int a = 1, b = 1, c;
  5.         c = a++ + b;
  6.         printf("%d, %d", a, b);
  7.     }

a) a = 1, b = 1
b) a = 2, b = 1
c) a = 1, b = 2
d) a = 2, b = 2
Answer: b
Clarification: None.

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

  1.     #include 
  2.     int main()
  3.     {
  4.         int a = 1, b = 1, d = 1;
  5.         printf("%d, %d, %d", ++a + ++a+a++, a++ + ++b, ++d + d++ + a++);
  6.     }

a) 15, 4, 5
b) 9, 6, 9
c) 9, 3, 5
d) Undefined (Compiler Dependent)
Answer: d
Clarification: None.

4. For which of the following, “PI++;” code will fail?
a) #define PI 3.14
b) char *PI = “A”;
c) float PI = 3.14;
d) none of the Mentioned
Answer: a
Clarification: None.

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

  1.     #include 
  2.     int main()
  3.     {
  4.         int a = 10, b = 10;
  5.         if (a = 5)
  6.         b--;
  7.         printf("%d, %d", a, b--);
  8.     }

a) a = 10, b = 9
b) a = 10, b = 8
c) a = 5, b = 9
d) a = 5, b = 8
Answer: c
Clarification: None.

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

  1.     #include 
  2.     int main()
  3.     {
  4.         int i = 0;
  5.         int j = i++ + i;
  6.         printf("%dn", j);
  7.     }

a) 0
b) 1
c) 2
d) Compile time error
Answer: b
Clarification: None.

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

  1.      #include 
  2.     int main()
  3.     {
  4.         int i = 2;
  5.         int j = ++i + i;
  6.         printf("%dn", j);
  7.     }

a) 6
b) 5
c) 4
d) Compile time error
Answer: a
Clarification: None.

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

  1.     #include 
  2.     int main()
  3.     {
  4.         int i = 2;
  5.         int i = i++ + i;
  6.         printf("%dn", i);
  7.     }

a) = operator is not a sequence point
b) ++ operator may return value with or without side effects
c) it can be evaluated as (i++)+i or i+(++i)
d) = operator is a sequence point
Answer: a
Clarification: None.

250+ TOP MCQs on For Loops and Answers

C language Objective Questions on “For Loops”. One shall practice these Objective Questions to improve their C programming skills needed for various interviews (campus interviews, walkin interviews, company interviews), placements, entrance exams and other competitive exams. These questions can be attempted by anyone focusing on learning C Programming language. They can be a beginner, fresher, engineering graduate or an experienced IT professional. Our C language Objective Questions come with detailed explanation of the answers which helps in better understanding of C concepts.

Here is a listing of C language Objective Questions on “For Loops” along with answers, explanations and/or solutions:

1. The C code ‘for(;;)’ represents an infinite loop. It can be terminated by ___________
a) break
b) exit(0)
c) abort()
d) terminate
Answer: a
Clarification: None.

2. What will be the correct syntax for running two variable for loop simultaneously?
a)

   for (i = 0; i < n; i++)
   for (j = 0; j < n; j += 5)

b)

for (i = 0, j = 0; i < n, j < n; i++, j += 5)

c)

   for (i = 0; i < n;i++){}
   for (j = 0; j < n;j += 5){}

d) none of the mentioned
Answer: b
Clarification: None.

3. Which for loop has range of similar indexes of ‘i’ used in for (i = 0;i < n; i++)?
a) for (i = n; i>0; i–)
b) for (i = n; i >= 0; i–)
c) for (i = n-1; i>0; i–)
d) for (i = n-1; i>-1; i–)
Answer: d
Clarification: None.

4. Which of the following cannot be used as LHS of the expression in for (exp1;exp2; exp3)?
a) variable
b) function
c) typedef
d) macros
Answer: d
Clarification: None.

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

  1.     #include 
  2.     int main()
  3.     {
  4.         short i;
  5.         for (i = 1; i >= 0; i++)
  6.             printf("%dn", i);
  7.  
  8.     }

a) The control won’t fall into the for loop
b) Numbers will be displayed until the signed limit of short and throw a runtime error
c) Numbers will be displayed until the signed limit of short and program will successfully terminate
d) This program will get into an infinite loop and keep printing numbers with no errors
Answer: c
Clarification: None.

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

  1.     #include 
  2.     void main()
  3.     {
  4.         int k = 0;
  5.         for (k)
  6.             printf("Hello");
  7.     }

a) Compile time error
b) hello
c) Nothing
d) Varies
Answer: a
Clarification: None.

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

  1.     #include 
  2.     void main()
  3.     {
  4.         int k = 0;
  5.         for (k < 3; k++)
  6.         printf("Hello");
  7.     }

a) Compile time error
b) Hello is printed thrice
c) Nothing
d) Varies
Answer: a
Clarification: None.

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

  1.     #include 
  2.     void main()
  3.     {
  4.         double k = 0;
  5.         for (k = 0.0; k < 3.0; k++)
  6.             printf("Hello");
  7.     }

a) Run time error
b) Hello is printed thrice
c) Hello is printed twice
d) Hello is printed infinitely
Answer: b
Clarification: None.

250+ TOP MCQs on Static Variables and Answers

C questions and puzzles on “Static Variables” along with answers, explanations and/or solutions:

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

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

a) 6 7
b) 6 6
c) 5 5
d) 5 6

Answer: a
Clarification: None.

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

  1.     #include 
  2.     void main()
  3.     {
  4.         static int x;
  5.         printf("x is %d", x);
  6.     }

a) 0
b) 1
c) Junk value
d) Run time error

Answer: a
Clarification: None.

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

  1.     #include 
  2.     static int x;
  3.     void main()
  4.     {
  5.         int x;
  6.         printf("x is %d", x);
  7.     }

a) 0
b) Junkvalue
c) Run time error
d) Nothing

Answer: b
Clarification: None.

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

  1.     #include 
  2.     void main()
  3.     {
  4.         static double x;
  5.         int x;
  6.         printf("x is %d", x);
  7.     }

a) Nothing
b) 0
c) Compile time error
d) Junkvalue

Answer: c
Clarification: None.

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

  1.     #include 
  2.     void main()
  3.     {
  4.         static int x;
  5.         if (x++ < 2)
  6.         main();
  7.     }

a) Infinite calls to main
b) Run time error
c) Varies
d) main is called twice

Answer: d
Clarification: None.

6. Which of following is not accepted in C?
a) static a = 10; //static as
b) static int func (int); //parameter as static
c) static static int a; //a static variable prefixed with static
d) all of the mentioned

Answer: c
Clarification: None.

7. Which of the following cannot be static in C?
a) Variables
b) Functions
c) Structures
d) None of the mentioned

Answer: d
Clarification: None.

250+ TOP MCQs on Pointers and Function Arguments and Answers

C MCQs (multiple choice questions) on “Pointers and Function Arguments”. One shall practice these MCQs to improve their C programming skills needed for various interviews (campus interviews, walkin interviews, company interviews), placements, entrance exams and other competitive exams. These questions can be attempted by anyone focusing on learning C Programming language. They can be a beginner, fresher, engineering graduate or an experienced IT professional. Our multiple choice questions come with detailed explanation of the answers which helps in better understanding of C concepts.

Here is a listing of C multiple choice questions on “Pointers and Function Arguments” along with answers, explanations and/or solutions:

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

  1.     #include 
  2.     void foo(int*);
  3.     int main()
  4.     {
  5.         int i = 10;
  6.         foo((&i)++);
  7.     }
  8.     void foo(int *p)
  9.     {
  10.         printf("%dn", *p);
  11.     }

a) 10
b) Some garbage value
c) Compile time error
d) Segmentation fault/code crash
Answer: c
Clarification: None.

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

  1.     #include 
  2.     void foo(int*);
  3.     int main()
  4.     {
  5.         int i = 10, *p = &i;
  6.         foo(p++);
  7.     }
  8.     void foo(int *p)
  9.     {
  10.         printf("%dn", *p);
  11.     }

a) 10
b) Some garbage value
c) Compile time error
d) Segmentation fault
Answer: a
Clarification: None.

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

  1.     #include 
  2.     void foo(float *);
  3.     int main()
  4.     {
  5.         int i = 10, *p = &i;
  6.         foo(&i);
  7.     }
  8.     void foo(float *p)
  9.     {
  10.         printf("%fn", *p);
  11.     }

a) 10.000000
b) 0.000000
c) Compile time error
d) Undefined behaviour
Answer: b
Clarification: None.

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

  1.     #include 
  2.     int main()
  3.     {
  4.         int i = 97, *p = &i;
  5.         foo(&i);
  6.         printf("%d ", *p);
  7.     }
  8.     void foo(int *p)
  9.     {
  10.         int j = 2;
  11.         p = &j;
  12.         printf("%d ", *p);
  13.     }

a) 2 97
b) 2 2
c) Compile time error
d) Segmentation fault/code crash
Answer: a
Clarification: None.

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

  1.     #include 
  2.     int main()
  3.     {
  4.         int i = 97, *p = &i;
  5.         foo(&p);
  6.         printf("%d ", *p);
  7.         return 0;
  8.     }
  9.     void foo(int **p)
  10.     {
  11.         int j = 2;
  12.         *p = &j;
  13.         printf("%d ", **p);
  14.     }

a) 2 2
b) 2 97
c) Undefined behaviour
d) Segmentation fault/code crash
Answer: a
Clarification: None.

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

  1.     #include 
  2.     int main()
  3.     {
  4.         int i = 11;
  5.         int *p = &i;
  6.         foo(&p);
  7.         printf("%d ", *p);
  8.     }
  9.     void foo(int *const *p)
  10.     {
  11.         int j = 10;
  12.         *p = &j;
  13.         printf("%d ", **p);
  14.     }

a) Compile time error
b) 10 10
c) Undefined behaviour
d) 10 11
Answer: a
Clarification: None.

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

  1.     #include 
  2.     int main()
  3.     {
  4.         int i = 10;
  5.         int *p = &i;
  6.         foo(&p);
  7.         printf("%d ", *p);
  8.         printf("%d ", *p);
  9.     }
  10.     void foo(int **const p)
  11.     {
  12.         int j = 11;
  13.         *p = &j;
  14.         printf("%d ", **p);
  15.     }

a) 11 11 11
b) 11 11 Undefined-value
c) Compile time error
d) Segmentation fault/code-crash
Answer: b
Clarification: None.

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

  1.     #include 
  2.     int main()
  3.     {
  4.         int i = 10;
  5.         int *const p = &i;
  6.         foo(&p);
  7.         printf("%dn", *p);
  8.     }
  9.     void foo(int **p)
  10.     {
  11.         int j = 11;
  12.         *p = &j;
  13.         printf("%dn", **p);
  14.     }

a) 11 11
b) Undefined behaviour
c) Compile time error
d) Segmentation fault/code-crash
Answer: a
Clarification: None.

9. Which of the following is the correct syntax to send an array as a parameter to function?
a) func(&array);
b) func(#array);
c) func(*array);
d) func(array[size]);
Answer: a
Clarification: None.