C Interview Questions and Answers (Page 2)

16) The default case is necessary to use in switch statement?

No, it's not necessary to use the default. But using default is a good programming technique, that must be used. If variable or expression does not match with any given case values, default case executed.

17) Can we use default case anywhere in the switch statement block?

Yes, of course. You can use default case anywhere with in the switch statement. It is not necessary to write default case at the end of the cases.

18) What happens if break keyword is not included after the case body?

break is optional in switch statements, if break does not exist, program's execution will move to next case and executes statements written within that next case body.

int a=2;
    case 1:
        printf(“one ”);
    case 2:
        printf(“two ”);
    case 3:
        printf(“three ”);
        printf(“other ”);

Here output will be two three other.

19) How will you differentiate ++a and a++?

++ is an increment operator, which increments the the value of a variable. ++a is pre increment, where value will be incremented first and then expression evaluate. a++ is a post increment, where expression evaluates first and then value increments.

20) Can you make a variable const and volatile both?

Yes, it is possible that a variable can be const and volatile, the value of that variable will not change in the code, but it can be change outside the code due to hardware or other method. Hence volatile can be applied with const.

21) Can printf() function be used in if condition?

Yes, because printf() returns integer value (that is total number of printed characters). And In if condition, a non-zero value evaluated as TRUE, and zero evaluated as FALSE.

if( printf(“Hello, World”) )

Here, printf() will return 13 (total number printed characters), so condition is true.

22) Write a statement to check whether any number is EVEN or ODD ?

It can be done using ternary (? :) operator, here is a statement.

int num=113;

23) What is the limitation of ternary operator, comparing with if statement?

In ternary operator, ? : (In case of TRUE or FALSE) only one C statement can use, but in if statement, we can use more than one statement.

24) What is sizeof() ?

It is a built in operator in c language, it returns the size of any variable/value in bytes.


25) What is difference between these two constants 10.05, 10.05f ?

10.05 is a double constant while 10.05f is a float constant, in c language 10.05 (any floating value without followed by ‘f') is a double constant value.

26) What are the difference among getch(),getche(),getchar()?

These all functions are used to get a single character from keyboard, but there are following differences.

getch() -It takes input, but not echo the character on console, but requires enter key.

getche() -It takes input, but not echo character and does not requires enter key.

getchar() -It takes input, echo character and requires enter key.

27) Can a C variable/identifier name starts with a digits and what are the maximum length of a variable/identifier name?

No, variable/identifier starts with a character or underscore. There are 32 characters can be used as a variable/identifier name.

28) Can we use % (modulus) operator with floating point number?

No, It will be an error, if you want to find remainder with floating point number, you should use fmod() function.

29) If we are using positive and negative number with % (modulus) operator, then what sign will be in result.

In C language, nominator sign will be taken in result.

30) How many types of errors you know in C language?

There are four types are errors are come in c program:

  1. Compiler Error or Syntax error
  2. Linker Error
  3. Run time error
  4. Logical error

Comments and Discussions!

Load comments ↻

Copyright © 2024 www.includehelp.com. All rights reserved.