C Interview Questions
C Interview Questions
C INTERVIEW QUESTIONS
1. Write a program to print "hello world" without using semicolon?
#include<stdio.h>
void main()
{
if(printf("hello world")){}
}
Scope of a variable is the part of the program where the variable may directly be accessible. In C, all
identifiers are lexically (or statically) scoped.
NULL is used to indicate that the pointer doesn’t point to a valid location. Ideally, we should initialize
pointers as NULL if we don’t know their value at the time of declaration. Also, we should make a pointer
NULL when memory pointed by it is deallocated in the middle of a program.
We can pass value to function by one of the two ways: call by value or call by reference. In case of call by
value, a copy of value is passed to the function, so original value is not modified. But in case of call by
reference, an address of value of passed to the function, so original value is modified
malloc()
calloc()
realloc()
free()
In C, every local variable of a function is known as automatic (auto) variable. Let's explain with an
example:
void f()
{
int i ;
auto int j;
}
1
3RI Technologies Pvt Ltd
7. Can we compile a program without main() function?
The ++ operator is called the increment operator. When the operator is placed before the variable
(++var), the variable is incremented by 1 before it is used in the expression. When the operator is placed
after the variable (var++), the expression is evaluated, and then the variable is incremented by 1.
The same holds true for the decrement operator (--). When the operator is placed before the variable,
you are said to have a prefix operation. When the operator is placed after the variable, you are said to
have a postfix operation.
You can't declare a static variable without defining it as well (this is because the storage class
modifiers static and extern are mutually exclusive). A static variable can be defined in a header file, but
this would cause each source file that included the header file to have its own private copy of the
variable, which is probably not what was intended.
10. Other than in a ‘FOR’ statement, when is the comma operator used?
11. What is the difference between “int main()” and “int main(void)” in C?
Both definitions work in C also, but the second definition with void is considered technically better as it
clearly specifies that main can only be called without any parameter.In C, if a function signature doesn’t
specify any argument, it means that the function can be called with any number of parameters or
without any parameters.
In C, printf() returns the number of characters successfully written on the output and scanf() returns
number of items successfully read.
13. In C programming, how do you insert quote characters (‘ and “) into the output screen?
2
3RI Technologies Pvt Ltd
To insert the quote character as part of the output, use the format specifiers \’ (for single quote), and \”
(for double quote).
An ampersand & symbol must be placed before the variable name whatnumber. Placing & means
whatever integer value is entered by the user is stored at the “address” of the variable name. This is a
common mistake for programmers, often leading to logical errors.
15. What will be the outcome of the following conditional statement if the value of variable s is 10?
The outcome will be TRUE. Since the value of s is 10, s >= 10 evaluates to TRUE because s is not greater
than 10 but is still equal to 10. s< 25 is also TRUE since 10 is less then 25. Just the same, s!=12, which
means s is not equal to 12, evaluates to TRUE. The && is the AND operator, and follows the rule that if
all individual conditions are TRUE, the entire statement is TRUE.
Yes, they both do the exact same thing, which is to accept the next key pressed by the user and
assign it to variable named letter.
17. What is the use of a semicolon (;) at the end of every program statement?
A semicolon acts as a delimiter, so that the compiler knows where each statement ends, and can
proceed to divide the statement into smaller elements for syntax checking.
We cannot pass the entire array to a function. Instead, you pass to it a pointer that will point to the
array first element in memory. To do this, you indicate the name of the array without the brackets
The word void is a reserved word in C language. You cannot use reserved words as a user-defined
variable.
No. The exit() function is used to exit your program and return control to the operating system. The
return statement is used to return from a function and return control to the calling function. If you issue
a return from the main() function, you are essentially returning control to the calling function, which is
the operating system. In this case, the return statement and exit() function are similar.