INTERVIEW QUESTION FROM “C” PROGRAMMING

course34

 

INTERVIEW QUESTION FROM “C” PROGRAMMING
1. What is a pointer on pointer?

A pointer to a pointer is a variable, like any other variable, but that holds the address of the variable. That variable just happens to be a pointer. You can use them when you need to return a pointer to some memory on the heap, but not using the return value.

2. Distinguish between malloc() and calloc() memory allocation.

There are two major differences between malloc and calloc in C programming language: first, in the number of arguments. The malloc() takes a single argument, while calloc() takes two.
Second, malloc() does not initialize the memory allocated, while calloc() initializes the allocated memory to ZERO.
Retrieved from- cs-fundamentals.com
3. Explain the syntax for for loop.
The syntax of a for loop in C programming language is −
for (init; condition; increment) {
statement(s);
}

4. How a negative integer is stored?
Positive integers are generally stored as simple binary numbers (1 is 1, 10 is 2, 11 is 3 and so on). Negative integers are stored as the two’s complement of their absolute value.

5. What is a static variable?
In computer programming, a static variable is a variable that has been allocated statically so that its lifetime or “extent” extends across the entire run of the program. The static keyword is used in C and related languages both for static variablesand other concepts.
6. What is a NULL pointer?
Null pointer is a special reserved value of a pointer. A pointer of any type has such a reserved value. Formally, each specific pointer type ( int * , char * etc.) has its own dedicated null-pointer value. Conceptually, when a pointer has that nullvalue it is not pointing anywhere.

7. What is the purpose of extern storage specifier?
A variable declared with the extern storage-class specifier is a reference to a variable with the same name defined at the external level in any of the source files of the program. The internal extern declaration is used to make the external-level variable definition visible within the block. Unless otherwise declared at the external level, a variable declared with the extern keyword is visible only in the block in which it is declared.

8. Explain the purpose of the function sprint().
Syntax:
int sprint(char *str, const char *string, …);
sprintf stands for “String print”. Instead of printing on console, it store output on char buffer which are specified in sprint.
9. What is the meaning of base address of the array?
A base address is a unique location in primary storage (or main memory) that serves as a reference point for other memory locations called absolute addresses.
In order to obtain an absolute address, a specific displacement (or offset) value is added to the base address. In primary storage, all addresses literally comprise fixed-length sequences of bits that stand for positive whole numbers usually expressed in hexadecimal form. For example, a base address might indicate the beginning of a program loaded into primary storage. The absolute address of each individual program instruction could be specified by adding a displacement to the base address.

10. What is a dangling pointer?
Dangling pointers arise when an object is deleted or de-allocated, without modifying the value of the pointer, so that the pointer still points to the memory location of the de-allocated memory.In short pointer pointing to non-existing memory location is called dangling pointer.

 

No comments yet! You be the first to comment.

Leave a Reply

Your email address will not be published. Required fields are marked *