C Interview Questions and Answers

|   473512

C Interview Questions and Answers

1)  How can we construct an increment statement or decrement statement in C?

Answer: We can do this in two different ways. 1) By using the increment operator ++ and decrement operator. For example, the statement “i++” means to increment the value of x by 1. Likewise, the statement “x –” means to decrement the value of x by 1. 2) The 2nd  way of writing increment statements is to use the conventional + plus sign or minus sign. In the case of “i++, another way to write it is “i = i +1.

2) List the different storage class specifiers in C?

Answer: static, auto, extern, register

3) Some Programmers debug their programs by placing comment symbols on some of the codes instead of deleting it. How does this aid in debugging?

Answer: Using comment symbols “/* */ ” in  a code, also called as commenting out, is a way of segregate some codes that you think maybe causing errors in the code, without deleting the program. The aim is that if the code is in fact correct, we can simply remove the comment symbols and continue on. It also saves you time and effort on having to retype the codes if you have deleted it in the first place.

4) What is call by value and call by reference in C Programming language?

We can pass value to function by two different ways: call by value and call by reference. In case of call by value, a copy of value is passed to the function, so original value is not modified in the call by value. But in case of call by reference, an address of value is passed to the function, so original value is modified in the call by reference.

5) How can we replace the following statement by using WHILE Loop?

for (x=1; x<=100; x++)
printf ("%d ", x *x );

Answer:
x=1;
while (x<=100)

{
printf ("%d ", x * x);
x++;
}

6) Name the different functions are used for dynamic memory allocation in C Program?

Answer:
malloc(),calloc(),realloc(),free()

7) Explain about spaghetti programming?

Answer: Spaghetti programming refers to programs that tend to get tangled and overlapped throughout the codes. This unorganized approach to coding is usually attributed to lack of experience on the part of the programmer. Spaghetti coding makes a program complex and analysing the codes difficult, and so must be avoided as much as possible.

8) Write the programming code to swap two numbers without using third variable?

int x=10, y=20;      

printf("Before swap x=%d y=%d",x,y);        

y=x-y;   &nb

x=x-y;

printf(

9) In C program, how we can insert quote characters (‘ and ”) into the output screen?

Answer: This is a common problem for freshers/beginners because quotes are normally part of a “printf” statement in program. If we want to  insert the quote character as part of the output, use the format specifiers , and ” (for double quote) , ’ (for single quote).

10) Differentiate between the = symbol and == symbol?

Answer: The = symbol is

11) For what purpose we use a ‘ character?

<

12) What is modular programming?

An

13) Can the curly brackets { }be used to enclose a single line of code?

Answer: While curly brackets are mai

14) Check these operators and find out the incorrect operator and explain why? ( >=, <=, <>, ==)

Answer: The incorrect is <>. While this operator is correctly interpreted as “not equal to”” in writing conditional statements, it is not the proper operator to be used in C program. Instead, the operator!=  must be used to indicate “not equal to “condition.15) What is ++X and X++ Operator?

Answ

16) Can we use “ int”” data type to store the value 32768? Why?

Answer: No. “ int”” data type is capable of storing values from -32768 to 32767. To store 32768, you can use “ “long int”” instead of “int”. You can also use “ “unsigned int”, assuming you

17) Explain about the header files and what are the uses of header files in C program?

Answer: Header files are also called as library files. They contain 2 essential things: the definitions and prototypes of functions being used in a code. Simply put, commands that you use in C programming codes are actually functions that are defined from

18) Can we use two or more operators such as and be combined in a single line of program?

Answer: Yes, it’s perfectly valid to combine operators, especially if the need comes.

For example: you can have a code like “printf (“Good ‘Morning ”) ” to output the text “Good”” on the first line and “Morning”” enclosed in single quotes to appear on the next two lines. 

19) Why we are not declaring all the header files in every C p

Answer: The choice of declaring a header file at the top of C pr

20) List out the merits and demerits of array in C program?

Answer:

Merits:(b) It is not nece

(c) Array elements are stored in continuous memory location.

Demerit:

(a) We cannot change size of array at the run time. So Wastage of memory space.

(b) Array can store only similar type of data.

22) When we will use the “Void” keyword  in a function?

23) Write a loop statement that will show the following output:
for (b=1; b<=a; b++

printf("%s","*");

}printf(" ");

24) How can we generate random number

Answer: Random numbers are generated in C using the rand() command. For example: anyNum = rand() will generate any integer number beginning from 0, assuming that anyNum is a variable of type integer.

25) What is wrong in this statement?  scanf (%d, whatnumber);

Answer: This format is used f<

Answer: You

29) Is it possible to initializ

Answer: Yes, you don’t have to write a separa

Answer: To get the length of a strin

3

Answer: Reserved words are words that are part of the standard C language library. This

32) What is the different file extensions involved when coding in C?

Answer: Source codes in C are saved with .C file extension. Header files or library files have the .H file extension. Every time a program source code is successfully compiled, it creates an .OBJ object file, and

33) Explain about linked list?

34) Consider the below statement

Answer: FALSE. All reserved words must be written in lowercase; o

35) What are binary trees?

Answer: Binary trees are actually an extension of the concept of linked lists. A binary tree has two pointers, a left one and a right one. Each side can further branch to form additional nodes, which each node having two

 36) Is this program statement is valid? INT = 10.

Answer: Assuming that INT is a variable of type float, this statement is valid. One may think that INT is a reserved word and must not be used for other purposes. However, recall that reserved words are express in lowercase, so the C compiler will not inte

37) What is wrong with this program statement? void = 10;

An

38) What is a newline escape sequence?

Answer: A newline escape sequence is representfore the actual output expression or after. 

39) Explain about output redirection?

Answer: It is the process of transferring data to an alternative output source other than the display screen. Output redirection allows a program to have its outp

40) Write a simple code fragment that will check if a number i

Answer: If (num>=0)41) What is the difference between functions abs() and fabs()?<

Answer: These 2 fu

42) What does the function toupper() do?<

43) In C which function can be used to append a

Answer: The strcat function. It takes two parameters, the source string

44) Do these two program statements perform the

Answer:Yes, they both do the exact same thing, which is to accept the next key pressed by t

45) Differentiate between text files and binary files?

48) The % symbol has a special use in a printf statement. How can you place this character as

Answer: We can do this by using %% in the printf statement. For example, you can write pri

49) Explain the advan

Answer: Storing data o

50) What is calloc and malloc?

Answer:

feedback