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

Pipes and Cistern

Two pipes A and B can fill a tank in 6 hours and 4 hours respectively. If they are opened on alternate hours and if pipe A s opened first, in how many hours, the tank shall be full?

A large tanker can be filled by two pipes A and B in 60 min and 40 min respectively. How many minutes will it take to fill the tanker from empty state if B is used for first half of the time, and A and B fill it together for the other half?

A tank is filled by 3 pipes with uniform flow. The first two pipes operating simultaneously fill the tank in the same time during which the tank is filled by the third pipe alone. The 2nd pipe fills the tank 5 hours faster than first pipe and 4 hours slower than third pipe. The time required by first pipe is?

Two pipes A and B together can fill a cistern in 4 hours. Had they been opened separately, then B would have taken 6 hours more than A to fill the cistern. How much time will be taken by A to fill the cistern separately?

Two pipes A and B can fill a tank in 24 min and 32 min respectively. If both the pipes are opened simultaneously, after how much time B should be closed so that the tank is full in 18 min?

Two pipes A and B can fill a tank in 36 min and 45 min respectively. A water pipe C can empty the tank in 30 min. First A and B are opened. after 7 min, C is also opened. In how much time, the tank is full?

Two pipes can fill a cistern in 14 hours and 16 hours respectively. The pipes are opened simultaneously and it is found that due to leakage in the bottom it took 32 min more to fill the cistern. When the cistern is full, in what time will the leak empty it?

Bucket P has thrice the capacity as Bucket Q. It takes 60 turns for Bucket P to fill the empty drum. How many turns it will take for both the buckets P and Q, having each turn together to fill the empty drum?

Probability

In a class , 30 % of the students offered English, 20 % offered Hindi and 10 % offered Both.If a student is offered at random, what is the probability that he has offered English or Hindi?

In a lottery ,there are 10 prizes and 25 blanks.A lottery is drawn at random. what is the probability of getting a prize ?

Two dice are thrown simultaneously .what is the probability of getting two numbers whose product is even?

Two diced are tossed the probability that the total score is a prime number?

Two cards are drawn at random from a pack of 52 cards What is the probability that either both are black or both are queens?

Two dice are thrown together .What is the probability that the sum of the number on the two faces is divisible by 4 or 6?

A bag contains 6 white and 4 black balls .Two balls are drawn at random .Find the probability that they are of the same colour?

In a simultaneous throw of a pair of dice,find the probability of getting a total more than 7?

An unbiased die is tossed.Find the probability of getting a multiple of 3?

Problems on Ages

My brother is 3 years elder to me. My father was 28 years of age when my sister was born while my mother was 26 years of age when i was born. If my sister was 4 years of age when my brother was born,then what was the age my father and mother respectively when my brother was born?

Latest Job Notifications

Banking Jobs

बैंकिंग कार्मिक चयन संस्थान Institute of Banking Personnel Selection(IBPS) - 7855 पद - 29/07/2022 अंतिम तिथि

SSC Recruitment

कर्मचारी चयन आयोग (एसएससी) Staff Selection Commission (SSC) - 1411 पद - 29/07/2022 अंतिम तिथि

Jobs in Rajasthan

राजस्थान अधीनस्थ और मंत्रिस्तरीय सेवा चयन बोर्ड Rajasthan Subordinate and Ministerial Services Selection Board (RSMSSB) - 5546 पद - 22-Jul-2022 अंतिम तिथि

Railway Recruitment

उत्तर मध्य रेलवे भर्ती प्रकोष्ठ Railway Recruitment Cell(NCR) - 1659 पद - 01/08/2022 अंतिम तिथि

Jobs in West Bengal

इंडियन पोस्ट सर्विस Indian Post Service - 2357 पद - 19/08/2021 अंतिम तिथि - पश्चिम बंगाल पोस्टल सर्कल

Banking Jobs

भारतीय स्टेट बैंक State Bank of India(SBI) - 6100 पद - 26/07/2021 अंतिम तिथि - CRPD/APPR/2021-22/10

SSC Recruitment

कर्मचारी चयन आयोग Staff Selection Commission(SSC) - 25271 पद - 31/08/2021 अंतिम तिथि

Jobs in Madhya Pradesh

राष्ट्रीय स्वास्थ्य मिशन मध्य प्रदेश National Health Mission MP(NRHM) - 5215 पद - 22/06/2021 अंतिम तिथि

Jobs in Punjab

पंजाब स्टेट पावर कॉर्पोरेशन लिमिटेड Punjab State Power Corporation Limited (PSPCL) - 2632 पद - 20/06/2021 अंतिम तिथि

Jobs in Chhattisgarh

स्वास्थ्य सेवा निदेशालय, छत्तीसगढ़ Department of Health & Family Welfare, Chhattisgarh - 267 पद - 26/06/2021 अंतिम तिथि