C Programming Language – Interview Questions & Answers (Page -2)
What happens if break keyword is not included after the case body?
break is optional in switch statements, if break does not exists, program's execution will move to next case and execute their body.
Here output will be two three other.
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.
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.
printf() function can be used in if condition ?
Yes, because printf() returns integer value. And In if condition and non-zero value evaluated as a TRUE, and zero evaluated as a FALSE.
if( printf(“Hello, World”) )
Here, printf() will return 13 (total number printed characters), so condition is true.
Write a statement to check whether any number if EVEN or ODD ?
Yes, it can be done using ternary (? :) operator, here is a statement.
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.
What is sizeof() ?
It is a built in operator in c language, it returns the size of any variable/value in bytes.
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.
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.
-It takes input, but not echo the character on console, but requires enter key.
-It takes input, but not echo character and does not requires enter key.
-It takes input, echo character and requires enter key.
Can a c variable/identifier name starts with a digits & 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.
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.
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.
How many types of errors you know in C language?
There are four types are errors are come in c program:
- Compiler Error or Syntax error
- Linker Error
- Run time error
- Logical error