C Interview Questions and Answers

How do declare an array?

We can declare an array by specify its data type, name and the number of elements the array holds between square brackets immediately following the array name.

ex
int array_int[10]; 

Can we access array using pointer in C language?

Yes, by holding the base address of array into pointer, we can access the array using pointer.

What is a string? How do you know its length?

In C, a string is a character array which is terminated by a null character (‘’). The null character tells the string functions to end of the string.
The strlen() function can be used to measure the length of a string. It returns the total number of bytes taken by the string and it is not counted the null character in the string.

What is static memory allocation?

Allocated the memory at compile time called static memory allocation.It is fixed and can't be increased at runtime.

What is dynamic memory allocation?

Allocation of memory at the time of execution is called dynamic memory allocation. In C, It is done via using the standard library functions malloc() and calloc().

What functions are used for dynamic memory allocation in C language?

C provides four dynamic memory allocation functions, those are
malloc(), calloc(), realloc() and free()

What are the difference between malloc() and calloc()?

malloc(): The malloc() function takes only one argument and used toallocates single block of requested memory. It has garbage value initially.
calloc(): The calloc() function takes two arguments and used toallocates multiple block of requested memory. It initially initializes all bytes to zero.

Explain realloc()?

The realloc() function can change the size of a memory space allocated by the malloc() ,calloc() and realloc() itself.

The syntax for the realloc() function is
void *realloc(void *block, size_t size);
Here block is the pointer to the start of a piece of memory space previously allocated.
size specifies the total byte number you want to change to.

What free() function do?

The free() function can be release unused allocated memory by the malloc(), calloc(), or realloc() function.

What are enumerated or enum types?

The enumerated data type can be used to declare named integerconstants.Enumerators are defined with the keyword enum.
By default, the first enumname starts with the value of 0 and the value of each name in the
rest of the list increases by one from left to right.

enum days{SUN,MON,TUE,WED,THU,FRI,SAT};

where SUN represent 0 and MON to SAT respectively 1 to 6

we can also assign any integer values to enum names.

What Is a Structure?

Structure is a user-defined data type and collection of heterogeneous data items,that is collection of different variables with their data type.
The data items in a structure are called members of the structure,whereasvthe structure member can be refer via dot operator (.) with structure variable and arrow operator (->) with structure pointer variable.
for ex
structure student as:

struct student {
introll_number;
charname[30];
inttotal_marks;
} student1;

What Is a Union?

union is similar to a structure, except that the data items saved in the union are overlaid in order to share the same memory location. That is, they all share the same starting address.
The allocated size of a union is at least as large as the size of the largest data item in the list of the union members in memory.

Like a structure, you can reference a union’s members by using dot and arrow operator with it variable.

What are the differences between a union and a structure?

The major differences between structure and union are:

(i) In structure every member has its own memory whereas in union its members share the same member space.
(ii) In structure, it is possible to initialize all the members at the same time which is not possible in case of union. 

What is command line arguments?

The arguments that we pass to main() at command prompt are called command line arguments. These arguments are supplied at the time of invoking the program.
The main()function can take arguments as:main(int argc,char *argv[]) { }
The first argument argc is known as argument counter. It represents the number of arguments in the command line.The second argument argv is known as argument vector. It is an array of char type pointers that points to the command line arguments.Sizeof this array will be equal to the value of argc.

What is a preprocessor?

Preprocessor is a directive to the compiler to perform certain things before the actual compilation process begins.

What is the difference between pre increment and post increment operator?

Post-increment (ex: x++) returns a copy of the original value before increment itself. Pre-increment (ex: ++x) returns a copy of the original value plus 1.
Ex:
int i=0, j, k;
j=i++;
k=++i;
printf("%d %d %d ", i, j, k);

Output :> 2 0 2    

Latest Updates

Indian Geography

What is the approximate distance between earth and the moon?

Indian History

In which year was the battle of ‘Koregaon Bhima’ fought?

The approach that is very useful in organizing the content in history is.

General Knowledge of India

NITI Aayog stands for _____.

General Knowledge of MP

India’s first Ramayan art museum was established at?

Errors Identification

Read the sentence carefully and choose the option that has an error in it:
The management’s trusted employee was suspected of stealing large sum of money.

Read the sentence carefully and choose the option that has an error in it:
The teacher asked the child to repeat again because he spoke feebly.

Fill in the blank

Fill in the blank with the most appropriate preposition in the given sentence.
Let’s sit _________ the shade of this beautiful tree.

Choose the most appropriate determiner for the given sentence.
________of what he said was very sensible.

Substitution

Choose the option that substitutes the given phrase appropriately.
A work of art made by carving

Correct sentence

Choose the option that best transforms the sentence into its Indirect form:
‘What country do you come from?’ said the police officer.

Alternative Phrase

Choose the option that best explains the highlighted expression:
All human beings have feet of clay.

Fill in the blank

Choose an appropriate modal for the given sentence:
My doctor said that I_____ stop smoking as one of my lungs got infected.

Choose the appropriate prepositions for the given sentence:
My parents have been married ________ forty-nine years, but you can still see the love ________ their eyes.

Choose the appropriate conjunction for the given sentence:
______ it rains, the college will declare the holiday.

Antonyms

Choose the appropriate antonym for the highlighted word in the given sentence.
The family protracted their visit by several days.

Tenses

Choose the appropriate tenses to fill in the blanks in the given sentence:
Please _________ a noise. Ritu __________ to sleep.

Synonyms

Choose the appropriate synonym for the highlighted word in the given sentence.
Does he really expect us to believe such a flimsy excuse?