250+ TOP MCQs on Character Handling and Answers

C MCQs on “Character Handling – 1”.

1. Which header declares several functions useful for testing and mapping characters?
a) assert.h
b) stdio.h
c) ctype.h
d) errno.h
Answer: c
Clarification: The header declares several functions useful for testing and mapping characters.

2. The______function tests for any character for which isalpha or isdigit is true.
a) isxdigit()
b) isspace()
c) isalnum()
d) isupper()
Answer: c
Clarification: int isalnum(int c)
The isalnum function tests for any character for which isalpha or isdigit is true.

3. What does the following C code do?

a) checks if character is upper case
b) checks if character is lower case
c) tests for any control character
d) no function as such
Answer: c
Clarification:
int iscntrl( int c);
The iscntrl function tests for any control character.

4. What do the following C function do?

a) tests for only space character
b) tests for only digit
c) tests for only lower case
d) tests for any printing character
Answer: d
Clarification: int isgraph(int c);
The isgraph function tests for any printing character except space.

5. The isdigit function tests for any decimal-digit character.
a) true
b) false
Answer: a
Clarification: int isdigit(int c);
This function checks whether the passed character is a decimal digit.

6. Which function returns true only for the characters defined as lowercase letters?
a) islow()
b) islower()
c) isalpa()
d) isalnum()
Answer: b
Clarification: int islower( int c);
The islower function tests for any character that is a lowercase letter.

7. This function checks whether the passed character is white-space.
a) ispunct()
b) isgraph()
c) isspace()
d) isalpha()
Answer: c
Clarification: The isspace function tests for any character that is a standard white-space character.

8. The standard white-space characters are the following: space (‘ ‘), form feed (‘ f ‘),
newline (‘ n’) , horizontal tab (‘ tr), and vertlcal tab (‘ v’) can be tested with function.
a) ispunct()
b) isalpha()
c) isgraph()
d) isspace()
Answer: d
Clarification: The isspace function tests for any character that is a standard white-space character.

9. Which function tests for any character that is an uppercase letter.
a) iscntrl()
b) ispunct()
c) isdigit()
d) isupper()
Answer: d
Clarification: isupper() returns true only for the characters defined as uppercase letters.

10. The______function tests for any hexadecimal-digit character.
a) iscntrl()
b) ispunct()
c) isgraph()
d) isxdigit()
Answer: d
Clarification: int isxdigit( int c) ;
This function tests for any hexadecimal-digit character.

250+ TOP MCQs on Signal Handling and Answers

C MCQs on “Signal handling”.

1. Select the right statement.
a) synchronous signal occurs because of the action that your program takes
b) synchronous signal occurs because of action outside your program
c) asynchronous signal occurs because of the action that your program takes
d) division by zero is asynchronous
Answer: a
Clarification: Synchronous signal occurs because of the actions that your program takes.

2. What does raise functions declared in signal.h do?
a) reports a synchronous signal
b) let’s you specify handling of signals
c) reports a asynchronous signal
d) doesn’t let you specify handling of signals
Answer: a
Clarification: The function raise defined under the header file signal. h reports a synchronous signal.

3. What is the type declared by the header file signal.h?
a) sig_atomic_t
b) sig_signal_t
c) sig_signal_h
d) sig_stomic_h
Answer: a
Clarification: The only type declared in signal.h is sig_atomic_h.
This is of int type and used as a variable in signal handling.

4. Which among the given header file is used to handle different signals reported during program execution?
a) stdarg.h
b) assert.h
c) signal.h
d) setjmp.h
Answer: c
Clarification: signal.h is the header file that defines one type and two functions and many macros to handle different signals reported during the execution of the program.

5. Select the macro that abnormally terminates the program.
a) SIGILL
b) SIGTERM
c) SIGABRT
d) SIGFPE
Answer: c
Clarification: SIGABRT is the macro defined under the header file signal.h which terminates the program abruptly.

6. Which of the following is the correct description of the macro SIGFPE?
a) erroneous arithmetic operation such as zero divide
b) invalid access to storage
c) termination request sent to the program
d) receipt of the interactive attention signal
Answer: a
Clarification: SIGFPE is the macro defined under the header file signal.h which is an erroneous arithmetic operation such as zero divide, or operation resulting in overflow.

7. _________ gives receipt of an interactive attention signals.
a) SIGILL
b) SIGTERM
c) SIGINT
d) SIGFPE
Answer: c
Clarification: SIGINT gives receipt of an interactive attention signals.

8. The sig argument specifies the signal, which may be any signal except _______ and _________
a) SIG_DFL, SIG_IGN
b) SIGKILL, SIGSTOP
c) SIG_KILL, SIG_STOP
d) SIGCHLD, SIG_IGN
Answer: b
Clarification: The sigset() function is used to modify signal dispositions. The sig argument specifies the signal, it can be any signal except SIGKILL and SIGSTOP.

9. void (*signal(int sig, void (*func)(int)))(int);If the value of func is SIG_IGN then _________
a) the signal will be ignored
b) default handling for that signal will occur
c) The signal() function will fail to execute
d) the signal will be ignored
Answer: a
Clarification: SIG_IGN is one of the ways in signal() function in which receipt of the signal number sig is subsequently handled. The signal will be ignored if the value of func is SIG_IGN.

10. In the c library function void (*signal(int sig, void (*func)(int)))(int), which statement is true with respect to func?
a) func is a pointer to the function
b) func is pointer to sig
c) func is a static variable
d) func is a pointer that points to all type of data
Answer: a
Clarification: The declaration of the function signal() is given by
void (*signal(int sig, void (*func)(int)))(int). In this ‘func’ is a pointer to the function defined by the programmer or one of the following predefined functions:
SIG_DFL and SIG_IGN.

250+ TOP MCQs on Recursion and Answers

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

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

#include
main()
{
    int n;
    n=f1(4);
    printf("%d",n);
}
f1(int x)
{
    int b;
    if(x==1)
        return 1;
    else
        b=x*f1(x-1);
        return b;
}

a) 24
b) 4
c) 12
d) 10

Answer: a
Clarification: The above code returns the factorial of a given number using the method of recursion. The given number is 4 in the above code, hence the factorial of 4, that is, 24 will be returned.

2. The data structure used to implement recursive function calls _____________
a) Array
b) Linked list
c) Binary tree
d) Stack

Answer: d
Clarification: The compiler uses the data type stack for implementing normal as well as recursive function calls.

3. The principle of stack is __________
a) First in first out
b) First in last out
c) Last in first out
d) Last in last out

Answer: c
Clarification: A stack is a last in first out(LIFO) data type. This means that the last item to get stored in the stack is the first item to get out of it.

4. In the absence of a exit condition in a recursive function, the following error is given __________
a) Compile time error
b) Run time error
c) Logical error
d) No error

Answer: b
Clarification: When a recursive function is called in the absence of an exit condition, it results in an infinite loop due to which the stack keeps getting filled(stack overflow). This results in a run time error.

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

#include
main()
{
    int n,i;
    n=f(6);
    printf("%d",n);
}
f(int x)
{
    if(x==2)
            return 2;
    else
    {
        printf("+");
        f(x-1);
    }
}

a) ++++2
b) +++++2
c) +++++
d) 2

Answer: a
Clarification:
When x=6: ‘+’ is printed.
When x=5: ‘+’ is printed.
When x=4: ‘+’ is printed.
When x=3: ‘+’ is printed.
When x=2: 2 is printed.
Hence the output is: ++++2.

6. How many times is ‘a’ printed when the following C code is executed?

#include
main()
{
    int a;
    a=f1(10);
    printf("%d",a);
}
f1(int b)
{
    if(b==0)
        return 0;
    else
    {
        printf("a");
        f1(b--);
    }
}

a) 9 times
b) 10 times
c) 0 times
d) Infinite number of times

Answer: d
Clarification: Although we have specified the exit condition, the code above results in an infinite loop because we have used b- -(decrement operator) to call the recursive function. Due to this, the loop goes on infinitely. However, if we had used f1(b-1) instead, the answer would have been 10 times.

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

#include
main()
{
    int n=10;
    int f(int n);
    printf("%d",f(n));
}
int f(int n)
{
    if(n>0)
        return(n+f(n-2));
}

a) 10
b) 80
c) 30
d) Error

Answer: c
Clarification: The recursive function returns n+f(n-2) till 10>0.
Therefore, the above code will be evaluated as: 10+8+6+4+2, which is equal to 30.

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

#include
int main()
{
    printf("Hello");
    main();
    return 0;
}

a) Hello is printed once
b) Hello infinite number of times
c) Hello is not printed at all
d) 0 is returned

Answer: b
Clarification: in the above code, we are calling main() from main(), which is recursion. However, we have not defined any condition for the program to exit. Hence, “hello” will be printed infinite number of times. To prevent this, we need to define a proper exit condition in the recursive function.

9. What will be the output of the following C code if the input given to the code shown below is “”?

#include
#define NL 'n'
main()
{
    void f(void);
    printf("enter the wordn");
    f();
}
void f(void)
{
    char c;
    if((c=getchar())!=NL)
{
f();
    printf("%c",c);
}
return;
}

a)
b) infinite loop
c) yrdnuofnas
d) fnasyrdnuo

Answer: c
Clarification: The above code prints the reverse of the word entered. The recursive function terminates when getchar() is equal to null.

10. Iteration requires more system memory than recursion.
a) True
b) False

Answer: b
Clarification: Recursion requires more system memory than iteration due to the maintenance of stack.

250+ TOP MCQs on Increment and Decrement Operators and Answers

’s MCQs on C helps anyone preparing for placement in Capgemini and other companies. Anyone looking for Capgemini placement papers should practice these questions continuously for 2-3 months, thereby ensuring a top position in placements.

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

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

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

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

2. 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.         printf("%dn", *p++);
  7.     }

a) 10
b) 11
c) Garbage value
d) Address of i
Answer: a
Clarification: None.

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

  1.     #include 
  2.     void main()
  3.     {
  4.         int x = 97;
  5.         int y = sizeof(x++);
  6.         printf("X is %d", x);
  7.     }

a) X is 97
b) X is 98
c) X is 99
d) Run time error
Answer: a
Clarification: None.

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

  1.     #include 
  2.     void main()
  3.     {
  4.         int x = 4, y, z;
  5.         y = --x;
  6.         z = x--;
  7.         printf("%d%d%d", x,  y, z);
  8.     }

a) 3 2 3
b) 2 3 3
c) 3 2 2
d) 2 3 4
Answer: b
Clarification: None.

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

  1.     #include 
  2.     void main()
  3.     {
  4.         int x = 4;
  5.         int *p = &x;
  6.         int *k = p++;
  7.         int r = p - k;
  8.         printf("%d", r);
  9.     }

a) 4
b) 8
c) 1
d) Run time error
Answer: c
Clarification: None.

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

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

a) 6 -6 0 0
b) 6 -5 0 1
c) -6 -6 0 1
d) 6 -6 0 1
Answer: d
Clarification: None.

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

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

a) -4
b) -5
c) 4
d) -3
Answer: d
Clarification: None.

250+ TOP MCQs on For Loops and Answers

C helps anyone preparing for Accenture and other companies C interviews. One should practice these Objective Questions and answers continuously for 2-3 months to clear Accenture interviews on C Programming language.

Here is a listing of online C test questions on “For Loops” 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.         double k = 0;
  5.         for (k = 0.0; k < 3.0; k++);
  6.             printf("%lf", k);
  7.     }

a) 2.000000
b) 4.000000
c) 3.000000
d) Run time error
Answer: c
Clarification: None.

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

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

a) Hello
b) Infinite hello
c) Run time error
d) Nothing
Answer: d
Clarification: None.

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

  1.     #include 
  2.     int main()
  3.     {
  4.         int i = 0;
  5.         for (; ; ;)
  6.             printf("In for loopn");
  7.             printf("After loopn");
  8.     }

a) Compile time error
b) Infinite loop
c) After loop
d) Undefined behaviour
Answer: a
Clarification: None.

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

  1.     #include 
  2.     int main()
  3.     {
  4.         int i = 0;
  5.         for (i++; i == 1; i = 2)
  6.             printf("In for loop ");
  7.             printf("After loopn");
  8.     }

a) In for loop after loop
b) After loop
c) Compile time error
d) Undefined behaviour
Answer: a
Clarification: None.

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

  1.     #include 
  2.     int main()
  3.     {
  4.         int i = 0;
  5.         for (foo(); i == 1; i = 2)
  6.             printf("In for loopn");
  7.             printf("After loopn");
  8.     }
  9.     int foo()
  10.     {
  11.         return 1;
  12.     }

a) After loop
b) In for loop after loop
c) Compile time error
d) Infinite loop
Answer: a
Clarification: None.

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

  1.     #include 
  2.     int main()
  3.     {
  4.         int *p = NULL;
  5.         for (foo(); p; p = 0)
  6.             printf("In for loopn");
  7.             printf("After loopn");
  8.     }

a) In for loop after loop
b) Compile time error
c) Infinite loop
d) Depends on the value of NULL
Answer: b
Clarification: None.

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

  1.     #include 
  2.     int main()
  3.     {
  4.         for (int i = 0;i < 1; i++)
  5.             printf("In for loopn");
  6.     }

a) Compile time error
b) In for loop
c) Depends on the standard compiler implements
d) Depends on the compiler
Answer: c
Clarification: None.

250+ TOP MCQs on Static Variables and Answers

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

1. What will be the output of the following C code if these two files namely test.c and test1.c are linked and run?

  1.       -------file test.c-------
  2.     #include 
  3.     #include ""test.h""
  4.     int main()
  5.     {
  6.         i = 10;
  7.         printf(""%d "", i);
  8.         foo();
  9.     }
  10. 
    
  11.     -----file test1.c------
  12.     #include 
  13.     #include ""test.h""
  14.     int foo()
  15.     {
  16.         printf(""%dn"", i);
  17.     }
  18. 
    
  19.     -----file test.h-----
  20.     #include 
  21.     #include 
  22.     static int i;

a) 10 0
b) 0 0
c) 10 10
d) Compilation Error

Answer: a
Clarification: None.

2. Functions have static qualifier for its declaration by default.
a) True
b) False
c) Depends on the compiler
d) Depends on the standard

Answer: b
Clarification: None.

3. Is initialisation mandatory for local static variables?
a) Yes
b) No
c) Depends on the compiler
d) Depends on the standard

Answer: b
Clarification: None.

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

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

a) 11 12 11 12
b) 11 13 11 14
c) 11 12 11 13
d) Compile time error

Answer: b
Clarification: None.

5. Assignment statements assigning value to local static variables are executed only once.
a) True
b) False
c) Depends on the code
d) None of the mentioned

Answer: b
Clarification: None.

6. What is the format identifier for “static a = 20.5;”?
a) %s
b) %d
c) %f
d) Illegal declaration due to absence of data type

Answer: b
Clarification: None.

7. Which of the following is true for the static variable?
a) It can be called from another function
b) It exists even after the function ends
c) It can be modified in another function by sending it as a parameter
d) All of the mentioned

Answer: b
Clarification: None.

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

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

a) Output will be 0
b) Output will be 20
c) Output will be a garbage value
d) Compile time error due to redeclaration of static variable

Answer: a
Clarification: None.