C Programming Interview Questions Set 3

Categories: C Programming language

Ques.  What is an array in C?

Ans. An Array is a group of similar types of elements. It has a contiguous memory location. It makes the code optimized, easy to traverse and easy to sort. The size and type of arrays cannot be changed after its declaration.


Arrays are of two types:

a) One-dimensional array: One-dimensional array is an array that stores the elements one after the another.

Syntax:

data_type array_name[size];  

Multidimensional array: Multidimensional array is an array that contains more than one array.

Syntax:


data_type array_name[size];  

Example of an array:


#include <stdio.h>  

int main()  

{  

   int arr[5]={1,2,3,4,5}; //an array consists of five integer values.  

   for(int i=0;i<5;i++)  

   {  

       printf("%d ",arr[i]);  

   }  

    return 0;  

}  

Output:

1 2 3 4 5


Ques. What is a pointer in C?

A pointer is a variable that refers to the address of a value. It makes the code optimized and makes the performance fast. Whenever a variable is declared inside a program, then the system allocates some memory to a variable. The memory contains some address number. The variables that hold this address number is known as the pointer variable.


For example:


Data_type *p;  

The above syntax tells that p is a pointer variable that holds the address number of a given data type value.

Example of pointer

#include <stdio.h>  

int main()  

{  

   int *p; //pointer of type integer.  

   int a=5;  

   p=&a;  

   printf("Address value of 'a' variable is %u",p);  

    return 0;  

}  

Output:

Address value of 'a' variable is 428781252


Ques. What is the usage of the pointer in C?

a) Accessing array elements: Pointers are used in traversing through an array of integers and strings. The string is an array of characters which is terminated by a null character '\0'.

b) Dynamic memory allocation: Pointers are used in allocation and deallocation of memory during the execution of a program.

c) Call by Reference: The pointers are used to pass a reference of a variable to other function.

d) Data Structures like a tree, graph, linked list, etc.: The pointers are used to construct different data structures like tree, graph, linked list, etc.


Ques. What is a NULL pointer in C?

Ans. A pointer that doesn't refer to any address of value but NULL is known as a NULL pointer. When we assign a '0' value to a pointer of any type, then it becomes a Null pointer.


Ques. What is a far pointer in C?

Ans. A pointer which can access all the 16 segments (whole residence memory) of RAM is known as far pointer. A far pointer is a 32-bit pointer that obtains information outside the memory in a given section.


Top Blogs
C Functions ! What is a Function Published at:- Types of Function in C ! Library Function in C ! User Defined Function In C ! Function Definition Published at:- Functions that return multiple values -C Example Published at:- Functions with arguments and return values -C Examples Published at:- Functions with arguments and no return values. Published at:- Example of Function with no return type and no argument Published at:- Loops in C Published at:- Structure in C: Introduction Published at:- C Memory Management ! Dynamic memory allocation Published at:- Learn C Programming language with example Published at:- C Interview Questions And Answers Published at:- What values are printed when we run following? Published at:- C Program example: Input a number and print sum of its digits Published at:- Pointer declaration in C ,Address operator Published at:- C Language Interview Question and Answers Published at:- Benefits of C language over other programming languages Published at:- History of C Language : Introduction to C Programming Language Published at:- How does C Programming Language Work Published at:- Importance of C Programming Language Published at:- Input and Output Functions in C Published at:- Introduction to Implementation of Queue using Linked List Published at:- First C Program Published at:- Inception Of C Language Tutorial for Beginners Published at:- The C Compiler work in C language and its important Published at:- Program Structure with “Hello World” Example Published at:- C Programming Interview Questions Set 1 Published at:- C Programming Interview Questions Set 2 Published at:- C Programming Interview Questions Set 3 Published at:- C Programming Interview Questions Set 4 Published at:- C Programming Interview Questions Set 5 Published at:- C Programming Interview Questions Set 6 Published at:- C Programming Interview Questions Set 7 Published at:- C Programming Interview Questions Set 8 Published at:- C Programming Interview Questions Set 9 Published at:-
R4R.co.in Team
The content on R4R is created by expert teams.