C Programming Interview Question and Answer SET 1


1.  What is C?
C is a high level procedural language having low level function capability so it is also known as a middle level language.
2.  Why the name given ‘C’?
Because it is the successor of a language called ‘B’.
3. Which is the first operating system fully written in C language?
Unix
4. What are the applications of C Language?
Operating System Design
Compiler Design
Device Drivers
Network Protocols
Embedded Systems
Utilities
5. What is a Data type?
It is the property of variable which gives the domain and behavior of that variable. 
6. What is a dummy operator in C?
The + sign operator is known as a dummy operator because it has no effect on variable.
7.  Can a variable be both constant and volatile?
Yes. The const modifier means that this code cannot change the value of the variable, but that does not mean that the value cannot be changed by means outside this code. 
The function itself did not change the value of the timer, so it was declared const. However, the value was changed by hardware on the computer, so it was declared volatile. If a variable is both const and volatile, the two modifiers can appear in either order.
8. What is dummy function in C?
The function without any body part is known as dummy function

9.  What is the output of printf("%d") ?
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.
10. What is the difference between %d and %i?
%d always interpret the no as decimal but %i can interpret the no as octal when it starts with 0 and hexadecimal when it starts with 0x.  
11.  What is the difference between calloc() and malloc() ?
calloc(...) allocates a block of memory for an array of elements of a certain size. By default the block is initialized to 0. The total number of memory allocated will be (number_of_elements * size).
malloc(...) takes in only a single argument which is the memory required in bytes. malloc(...) allocated bytes of memory and not blocks of memory like calloc(...).
malloc(...) allocates memory blocks and returns a void pointer to the allocated space, or NULL if there is insufficient memory available.
calloc(...) allocates an array in memory with elements initialized to 0 and returns a pointer to the allocated space. calloc(...) calls malloc(...) in order to use the C++ _set_new_mode function to set the new handler mode.

12.  What is the difference between printf() and sprintf() ?
sprintf() writes data to the character array whereas printf(...) writes data to the standard output device.
13 What are the qualifiers in C?
const and volatile.
14.  Advantages of a macro over a function?
Macro gets to see the Compilation environment, so it can expand __ __TIME__ __FILE__ #defines. It is expanded by the preprocessor. 
For example, you can’t do this without macros
#define PRINT(EXPR) printf( #EXPR “=%d\n”, EXPR)
PRINT( 5+6*7 ) // expands into printf(”5+6*7=%d”, 5+6*7 );
You can define your mini language with macros:
#define strequal(A,B) (!strcmp(A,B)) 

15.  What is the difference between strings and character arrays?
A major difference is: string will have static storage duration, whereas as a character array will not, unless it is explicity specified by using the static keyword. 
Actually, a string is a character array with following properties:
* the multibyte character sequence, to which we generally call string, is used to initialize an array of static storage duration. The size of this array is just sufficient to contain these characters plus the terminating NUL character.
* it not specified what happens if this array, i.e., string, is modified.
* Two strings of same value[1] may share same memory area.

16.  Write down the equivalent pointer expression for referring the same element a[i][j][k][l] ?
a[i] == *(a+i)
a[i][j] == *(*(a+i)+j)
a[i][j][k] == *(*(*(a+i)+j)+k)
a[i][j][k][l] == *(*(*(*(a+i)+j)+k)+l)
 17. What are the modifiers in C?
short, long, signed, unsigned, near, far, huge
 18. How many type of assignment are there in C?
4 types
Simple : x=5
Compound: x+=5
Chained: x=y=z=0
Embedded: x=(y=10)+5
19.  Which bit wise operator is suitable for putting on a particular bit in a number?
The bitwise OR operator. In the following code snippet, the bit number 24 is turned ON:
some_int = some_int | KBit24;

20. Does there exist any other function which can be used to convert an integer or a float to a string?
Some implementations provide a nonstandard function called itoa(), which converts an integer to string.
#include
char *itoa(int value, char *string, int radix);
DESCRIPTION
The itoa() function constructs a string representation of an integer.
PARAMETERS
value: Is the integer to be converted to string representation.
string: Points to the buffer that is to hold resulting string.
The resulting string may be as long as seventeen bytes.
radix: Is the base of the number; must be in the range 2 - 36.
A portable solution exists. One can use sprintf():
char s[SOME_CONST];
int i = 10;
float f = 10.20;
sprintf ( s, “%d %f\n”, i, f );

Comments

Popular posts from this blog

Tips 01) self introduction in an interview

Computer Science Terminology

Why Failure Is Good for Success