1. What are C identifiers?

These are names given to various programming element such as variables, function, arrays.It is a combination of letter, digit and underscore.It should begin with letter. Backspace is not allowed.

2. What is logical error?

Logical error are caused by an incorrect algorithm or by a statement mistypes in such a way
► That it doesn't violet syntax of language.
► Difficult to find.

3. Can you please explain the difference between syntax vs logical error?

Syntax Error
► These involves validation of syntax of language.
► Compiler prints diagnostic message.
Logical Error
Logical error are caused by an incorrect algorithm or by a statement
► Mistyped in such a way that it doesn't violet syntax of language.
► Difficult to find.

4. Can we use any name in place of argv and argc as command line arguments?

yes we can use any user defined name in place of argc and argv.

5. What is recursion?

A recursion function is one which calls itself either directly or indirectly it must halt at a definite point to avoid infinite recursion.

6. What is actual argument?

Actual arguments are available in the function call. These arguments are given as constants or variables or expressions to pass the values to the function.

7. What is formal argument?

Formal arguments are the arguments available in the function definition. They are preceded by their own data type.

8. Can main () be called recursively?

Yes any function including main () can be called recursively.

9. Are the variables argc and argv are always local to main?

Yes they are local to main.

10. Do you know the use of "auto" keyword?

When a certain variable is declared with the keyword 'auto' and initialized to a certain value, then within the scope of the variable, it is reinitialized upon being called repeatedly.

Download Interview PDF

11. Do you know the purpose of "register" keyword?

It is used to make the computation faster.
The register keyword tells the compiler to store the variable onto the CPU register if space on the register is available. However, this is a very old technique. Todays processors are smart enough to assign the registers themselves and hence using the register keyword can actually slowdown the operations if the usage is incorrect.

12. What are the scope of static variables?

The scope of a static variable is local to the block in which the variable is defined. However, the value of the static variable persists between two function calls.

13. What is use of bit field?

Bit Fields allow the packing of data in a structure. This is especially useful when memory or data storage is at a premium.

14. Explain bitwise shift operators?

The bitwise operators are used for shifting the bits of the first operand left or right. The number of shifts is specified by the second operator.

15. Can you please explain the difference between exit() and _exit() function?

► Io buffers are flushed by exit() and executes some functions those are registered by atexit().
► _exit() ends the process without invoking the functions which are registered by atexit().

16. What is _exit() function?

_exit() does not cleanup work like closing file descriptor, file stream and so on.

17. What is exit() function?

exit() does cleanup work like closing file descriptor, file stream and so on.

18. Can you please explain the difference between strcpy() and memcpy() function?

► Memcpy() copies specific number of bytes from source to destinatio in RAM, where as strcpy() copies a constant / string into another string.
► Memcpy() works on fixed length of arbitrary data, where as strcpy() works on null-terminated strings and it has no length limitations.
► Memcpy() is used to copy the exact amount of data, whereas strcpy() is used of copy variable-length null terminated strings.

19. What is memcpy() function?

With memcopy(), the programmer needs to specify the size of data to be copied. strncpy() is similar to memcopy() in which the programmer specifies n bytes that need to be copied.

20. What is strcpy() function?

strcpy() copies a string until it comes across the termination character ''.

21. Can you please explain the difference between malloc() and calloc() function?

Both functions are used to dynamically allocate the memory.

22. What is malloc() function?

malloc contains garbage values.

23. What is calloc() function?

calloc initializes the allocated memory to 0 or Null.

24. What is fflush() function?

In ANSI, fflush() [returns 0 if buffer successfully deleted / returns EOF on an error] causes the system to empty the buffer associated with the specified output stream.

25. What is function prototype?

A function prototype is a mere declaration of a function. It is written just to specify that there is a function that exists in a program.

Download Interview PDF

26. What is C standard library?

The C standard library is the standard library for the C programming language, as specified in the ANSI C standard. It was developed at the same time as the C POSIX library, which is a super-set of it.

27. What is the scope of static variables in C Language?

Static variables in C have the scopes;

1. Static global variables declared at the top level of the C source file have the scope that they can not be visible external to the source file. The scope is limited to that file.

2. Static local variables declared within a function or a block, also known as local static variables, have the scope that, they are visible only within the block or function like local variables. The values assigned by the functions into static local variables during the first call of the function will persist / present / available until the function is invoked again.

The static variables are available to the program, not only for the function / block. It has the scope within the current compile. When static variable is declared in a function, the value of the variable is preserved , so that successive calls to that function can use the latest updated value. The static variables are initialized at compile time and kept in the executable file itself. The life time extends across the complete run of the program.

Static local variables have local scope. The difference is, storage duration. The values put into the local static variables, will still be present, when the function is invoked next time.

28. What is C Programming structure?

Structures provide a convenient method for handling related group of data of various data types.

Structure definition:

struct tag_name
{
data type member1;
data type member2;


}

Example:
struct library_books
{
char title[20];
char author[15];
int pages;
float price;
};

The keyword struct informs the compiler for holding fields ( title, author, pages and price in the above example). All these are the members of the structure. Each member can be of same or different data type.

The tag name followed by the keyword struct defines the data type of struct. The tag name library_books in the above example is not the variable but can be visualized as template for the structure. The tag name is used to declare struct variables.

Ex: struct library_books book1,book2,book3;

The memory space is not occupied soon after declaring the structure, being it a template. Memory is allocated only at the time of declaring struct variables, like book1 in the above example. The members of the structure are referred as - book1.title, book1.author, book1.pages, book1.price.

Unions

Unions are like structures, in which the individual data types may differ from each other. All the members of the union share the same memory / storage area in the memory. Every member has unique storage area in structures. In this context, unions are utilized to observe the memory space. When all the values need not assign at a time to all members, unions are efficient. Unions are declared by using the keyword union , just like structures.

Ex: union item {
int code;
float price;
};

The members of the unions are referred as - book1.title, book1.author, book1.pages, book1.price.

29. What is self-referential structure in C Programming?

A self-referential structure is one of the data structures which refer to the pointer to (points) to another structure of the same type. For example, a linked list is supposed to be a self-referential data structure. The next node of a node is being pointed, which is of the same struct type. For example,

typedef struct listnode {
void *data;
struct listnode *next;
} linked_list;

In the above example, the listnode is a self-referential structure – because the *next is of the type sturct listnode.

30. Explain the use of "auto" keyword in C Programming?

The keyword ‘auto' is used extremely rare. A variable is set by default to auto. The declarations:

auto int number; and int number;

has the same meaning. The variables of type static, extern and register need to be explicitly declared, as their need is very specific. The variables other than the above three are implied to be of ‘auto' variables. For better readability auto keyword can be used.

31. Do you know what are the properties of Union in C?

A union is utilized to use same memory space for all different members of union. Union offers a memory section to be treated for one variable type , for all members of the union. Union allocates the memory space which is equivalent to the member of the union , of large memory occupancy.

32. Tell me what is the purpose of "register" keyword in C Language?

The keyword ‘register' instructs the compiler to persist the variable that is being declared , in a CPU register.

Ex: register int number;

The persistence of register variables in CPU register is to optimize the access. Even the optimization is turned off; the register variables are forced to store in CPU register.

33. What is the difference between strcpy() and memcpy() function in C Programming?

The following are the differences between strcpy() and memcpy():

- memcpy() copies specific number of bytes from source to destinatio in RAM, where as strcpy() copies a constant / string into another string.

- memcpy() works on fixed length of arbitrary data, where as strcpy() works on null-terminated strings and it has no length limitations.

- memcpy() is used to copy the exact amount of data, whereas strcpy() is used of copy variable-length null terminated strings.

34. Do you know what is the purpose of "extern" keyword in a function declaration?

The keyword ‘extern' indicates the actual storage of the variable is visible , or body of a function is defined elsewhere, commonly in a separate source code. This extends the scope of the variables or functions to be used across the file scope.

Example:
extern int number;

35. What is the difference between malloc() and calloc() function in C Language?

The following are the differences between malloc() and calloc():

- Byte of memory is allocated by malloc(), whereas block of memory is allocated by calloc().

- malloc() takes a single argument, the size of memory, where as calloc takes two parameters, the number of variables to allocate memory and size of bytes of a single variable

- Memory initialization is not performed by malloc() , whereas memory is initialized by calloc().

- malloc(s) returns a pointer with enough storage with s bytes, where as calloc(n,s) returns a pointer with enough contiguous storage each with s bytes.

36. What is function prototype in C Language?

The basic definition of a function is known as function prototype. The signature of the function is same that of a normal function, except instead of containing code, it always ends with semicolon.

When the compiler makes a single pass over each and every file that is compiled. If a function call is encountered by the compiler, which is not yet been defined, the compiler throws an error.

One of the solution for the above is to restructure the program, in which all the functions appear only before they are called in another function.

Another solution is writing the function prototypes at the beginning of the file, which ensures the C compiler to read and process the function definitions, before there is a change of calling the function. If prototypes are declared, it is convenient and comfortable for the developer to write the code of those functions which are just the needed ones.

37. Do you know the difference between exit() and _exit() function in C?

The following are the differences between exit() and _exit() functions:

- io buffers are flushed by exit() and executes some functions those are registered by atexit().

- _exit() ends the process without invoking the functions which are registered by atexit().

38. Tell us the use of fflush() function in C Language?

In ANSI, fflush() [returns 0 if buffer successfully deleted / returns EOF on an error] causes the system to empty the buffer associated with the specified output stream.
It undoes the effect of any ungetc() function if the stream is open for input. The stream remains open after the call.
If stream is NULL, the system flushes all open streams.

However, the system automatically deletes buffers when the stream is closed or even when a program ends normally without closing the stream.

39. Tell me the use of bit field in C Language?

Bit Fields allow the packing of data in a structure.

This is especially useful when memory or data storage is at a premium

The maximum length of the field should be less than or equal to the integer word length of the computer.some compilers may allow memory overlap for the fields.Some store the next field in the next word.
C lets us do this in a structure definition by putting :bit length after the variable:
struct pack
{
unsigned int funny_int:9;
}p;

Also, Boolean datatype flags can be stored compactly as a series of bits using the bits fields. Each Boolean flag is stored in a separate bit.

40. Do you know what are bitwise shift operators in C Programming?

The bitwise operators are used for shifting the bits of the first operand left or right. The number of shifts is specified by the second operator.

Expression << or >> number of shifts

Ex:

number<<3;/* number is an operand - shifts 3 bits towards left*/
number>>2; /* number is an operand – shifts 2 bits towards right*/

The variable number must be an integer value.

For leftward shifts, the right bits those are vacated are set to 0. For rightward shifts, the left bits those are vacated are filled with 0's based on the type of the first operand after conversion.

If the value of ‘number' is 5, the first statement in the above example results 40 and stored in the variable ‘number'.

If the value of ‘number' is 5, the second statement in the above example results 0 (zero) and stored in the variable ‘number'.

Download Interview PDF

41. Explain the advantages of using macro in C Language?

In modular programming, using functions is advisable when a certain code is repeated several times in a program. However, everytime a function is called the control gets transferred to that function and then back to the calling function. This consumes a lot of execution time. One way to save this time is by using macros. Macros substitute a function call by the definition of that function. This saves execution time to a great extent.

42. What is #pragma statements?

The #pragma Directives are used to turn ON or OFF certain features. They vary from compiler to compiler.
Examples of pragmas are:

#pragma startup // you can use this to execute a function at startup of a program
#pragma exit // you can use this to execute a function at exiting of a program
#pragma warn –rvl // used to suppress return value not used warning
#pragma warn –par // used to suppress parameter not used warning
#pragma warn –rch // used to suppress unreachable code warning

43. Tell me what is NULL pointer in C?

A null pointer does not point to any object.
NULL and 0 are interchangeable in pointer contexts.Usage of NULL should be considered a gentle reminder that a pointer is involved.
It is only in pointer contexts that NULL and 0 are equivalent. NULL should not be used when another kind of 0 is required.

44. Do you know pointer in C?

A pointer is an address location of another variable. It is a value that designates the address or memory location of some other value (usually value of a variable). The value of a variable can be accessed by a pointer which points to that variable. To do so, the reference operator (&) is pre-appended to the variable that holds the value. A pointer can hold any data type, including functions.

45. Do you have any idea how to compare array with pointer in C?

The following declarations are NOT the same:
char *p;
char a[20];

The first declaration allocates memory for a pointer; the second allocates memory for 20 characters.