C Interview Questions Part 20

Q:Can include records end up being nested?
A:Certainly. Incorporate records might be nested any number regarding situations. So long as you use precautionary actions, you can stay away from including the same report two times. In the past, nesting header records appeared to be noticed since awful licensed users training, because doing so complicates that dependency administering perform in the help make system and therefore slows along collection. Nearly all today’s famous compilers constitute because of this frustration through putting into action any idea referred to as pre compiled headers, through which almost all headers in addition to linked dependencies tend to be saved in the pre compiled state.

A good number of developers love to create a custom made header report which includes #include phrases for each header necessary for every module. This can be completely satisfactory and may aid stay away from potential wounds with regards to #include records, for example by chance omitting a good #include report in the module.

Q:What is a null pointer?
A:There are times when it’s necessary to have a pointer that doesn’t point to anything. The macro NULL, defined in , has a value that’s guaranteed to be different from any valid pointer. NULL is a literal zero, possibly cast to void* or char*.

Some people, notably C++ programmers, prefer to use 0 rather than NULL.
The null pointer is used in three ways:
1) To stop indirection in a recursive data structure.
2) As an error value.
3) As a sentinel value.

Q:What is the difference between printf() and sprintf()?
A:sprintf() writes data to the character array whereas printf(...) writes data to the standard output device.

Q:What is the output of printf("%d") ?
A:1. When we write printf("%d",x); this means compiler will print the value of x. But as here, there is nothing after %d so compiler will show in output window garbage value.

2. When we use %d the compiler internally uses it to access the argument in the stack (argument stack). Ideally compiler determines the offset of the data variable depending on the format specification string. Now when we write printf("%d",a) then compiler first accesses the top most element in the argument stack of the printf which is %d and depending on the format string it calculated to offset to the actual data variable in the memory which is to be printed. Now when only %d will be present in the printf then compiler will calculate the correct offset (which will be the offset to access the integer variable) but as the actual data object is to be printed is not present at that memory location so it will print what ever will be the contents of that memory location.

3. Some compilers check the format string and will generate an error without the proper number and type of arguments for things like printf(...) and scanf(...).
malloc()