C Programming Interview Questions and Answers - 3

Question: 11

What is the syntax for comments in C?

Below is the syntax for comments in C. The characters or words or anything which are given between “/*” and “*/”, won’t be considered by C compiler for compilation process. These will be ignored by C compiler during compilations.

Syntax : /* your comments here */

Question: 12

What is file pointer in C?

File pointer is a pointer which is used to handle and keep track on the files being accessed. A new data type called FILE is used to declare file pointer. This data type is defined in stdio.h file. File pointer is declared as FILE *fp. Where, ‘fb’ is a file pointer.

fopen() function is used to open a file that returns a FILE pointer. Once file is opened, file pointer can be used to perform I/O operations on the file. fclose() function is used to close the file.

Question: 13

What are runtime errors?

These are errors that occur which the program is being executed.

One common instance wherein run time errors can happen is when you are trying to divide a number by zero. When a run time errors occur, program execution will pause, showing which program line caused the error.

Question: 14

What is stack?

A stack is one form of data structure. Data is stored in stacks using the FILO (First In Last Out) approach.

At any particular instance, only the top of the stack is accessible. Which means that in order to retrieve data that is stored inside the stack, those on the upper part should be extracted first. Storing data in a stack is also referred to as a PUSH, while data retrieval is referred to as a POP.

Question: 15

What is stack memory allocation and dynamic memory allocation?

The compiler allocates the required memory space for a declared variable. By using the address of a operator, the reserved address is obtained and this address may be assigned to a pointer variable. Since, most of the declared variable has static memory, this way of assigning pointer value to a pointer variable is known as static memory allocation. Memory is assigned during compilation time.

Dynamic memory allocation: it uses functions such as malloc() or calloc() to get memory dynamically. If these functions are used to get memory dynamically and the values returned by these functions are assigned to pointer variables, such assignments are known as dynamic memory allocation. Memory is assigned during run time.

Related Questions