70+ C Programming Interview Questions

70+ C Programming Interview Questions

C Programming Interview Questions

 What is C language? 

C is a mid-level and procedural programming language. The Procedural programming language is otherwise called the organized programming language is a method in which expansive projects are separated into littler modules, and every module utilizes organized code. This system limits blunder and error.

Why is C known as a mother language? 

C is known as a mother language on the grounds that the greater part of the compilers and JVMs are written in C language. The greater part of the dialects which are created after C language has obtained vigorously from it like C++, Python, Rust, javascript, and so forth. It presents new center ideas like exhibits, capacities, record dealing with which are utilized in these dialects.

Why is C called a mid-level programming language? 

C is known as a mid-level programming language since it ties the low dimension and high - level programming language. We can utilize C language as a System programming to build up the working framework just as an Application programming to create menu driven client driven charging framework.

Who is the originator of C language? 

Dennis Ritchie.

When was C language created? 

C language was created in 1972 at chime research centers of AT&T.

What are the highlights of the C language? 

The principle highlights of C language are given underneath:

Straightforward: C is a basic language since it pursues the organized methodology, i.e., a program is broken into parts

Versatile: C is exceptionally convenient implies that once the program is composed can be kept running on any machine with next to zero alterations.

Mid Level: C is a mid-level programming language as it consolidates the low-level language with the highlights of the abnormal state language.

Organized: C is an organized language as the C program is broken into parts.

Quick Speed: C language is quick as it utilizes an incredible arrangement of information types and administrators.

Memory Management: C gives an inbuilt memory work that spares the memory and improves the productivity of our program.

Extensible: C is an extensible language as it can embrace new highlights later on.



What is the utilization of printf() and scanf() capacities? 

printf(): The printf() work is utilized to print the whole number, character, buoy and string esteems on to the screen.

Following are the arrangement specifier:

%d: It is an arrangement specifier used to print a whole number esteem.

%s: It is an organization specifier used to print a string.

%c: It is an organization specifier used to show a character esteem.

%f: It is a configuration specifier used to show a gliding point esteem.

scanf(): The scanf() work is utilized to take contribution from the client.

What is recursion in C? 

At the point when a capacity calls itself, and this procedure is known as recursion. The capacity that calls itself is known as a recursive capacity.

Recursive capacity comes in two stages:

Winding stage

Loosening up stage

Winding stage: When the recursive capacity calls itself, and this stage closes when the condition is come to.

Loosening up stage: Unwinding stage begins when the condition is come to, and the control comes back to the first call.

Case of recursion

#include  

int calculate_fact(int);

int principle()

{

int n=5,f;

f=calculate_fact(n);/calling a capacity

printf("factorial of a number is %d",f);

return 0;

}

int calculate_fact(int a)

{

if(a==1)

{

return 1;

}

else

return a*calculate_fact(a-1);/calling a capacity recursively.

}

Yield:

factorial of a number is 120

What is a cluster in C? 

An Array is a gathering of comparable sorts of components. It has a touching memory area. It makes the code enhanced, simple to cross and simple to sort. The size and sort of clusters can't be changed after its assertion.

Clusters are of two kinds:

One-dimensional cluster: One-dimensional exhibit is an exhibit that stores the components one after the another.

Linguistic structure:

data_type array_name[size];

Multidimensional cluster: Multidimensional exhibit is an exhibit that contains more than one cluster.

Linguistic structure:

data_type array_name[size];

Case of a cluster:

#include  

int primary()

{

int arr[5]={1,2,3,4,5};/a cluster comprises of five whole number qualities.

for(int i=0;i<5 i="" nbsp="" p="">
{

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

}

return 0;

}

Yield:

1 2 3 4 5


What is a pointer in C? 

A pointer is a variable that alludes to the location of an esteem. It makes the code enhanced and makes the execution quick. At whatever point a variable is pronounced inside a program, at that point the framework designates some memory to a variable. The memory contains some location number. The factors that hold this location number is known as the pointer variable.

For instance:

Data_type *p;

The above sentence structure tells that p is a pointer variable that holds the location number of a given information type esteem.

Case of pointer

#include  

int fundamental()

{

int *p;/pointer of sort number.

int a=5;

p=&a;

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

return 0;

}

Yield:

Address estimation of 'a' variable is 428781252


What is the utilization of the pointer in C? 

Getting to exhibit components: Pointers are utilized in navigating through a variety of numbers and strings. The string is a variety of characters which is ended by an invalid character '\0'.

Dynamic memory designation: Pointers are utilized in assignment and deallocation of memory amid the execution of a program.

Call by Reference: The pointers are utilized to pass a reference of a variable to other capacity.

Information Structures like a tree, chart, connected rundown, and so forth.: The pointers are utilized to develop distinctive information structures like tree, diagram, connected rundown, and so on.

What is a NULL pointer in C? 

A pointer that doesn't allude to any address of significant worth however NULL is known as a NULL pointer. When we dole out a '0' esteem to a pointer of any kind, at that point it turns into a Null pointer.

What is a far pointer in C? 

A pointer which can get to all the 16 portions (entire home memory) of RAM is known as far pointer. A far pointer is a 32-bit pointer that acquires data outside the memory in a given segment.

What is dangling pointer in C? 

On the off chance that a pointer is pointing any memory area, yet in the interim another pointer erases the memory involved by the principal pointer while the main pointer still indicates that memory area, the primary pointer will be known as a dangling pointer. This issue is known as a dangling pointer issue.

Dangling pointer emerges when an article is erased without adjusting the estimation of the pointer. The pointer focuses to the deallocated memory.

How about we see this through a precedent.

#include 

void principle()

{

int *ptr = malloc(constant esteem);/assigning a memory space.

free(ptr);/ptr turns into a dangling pointer.

}

In the above precedent, at first memory is assigned to the pointer variable ptr, and afterward the memory is deallocated from the pointer variable. Presently, pointer variable, i.e., ptr turns into a dangling pointer.

The most effective method to beat the issue of a dangling pointer

The issue of a dangling pointer can be overwhelmed by relegating a NULL incentive to the dangling pointer. We should comprehend this through a precedent:

#include 

void principle()

{

int *ptr = malloc(constant esteem);/dispensing a memory space.

free(ptr);/ptr turns into a dangling pointer.

ptr=NULL;/Now, ptr is never again a dangling pointer.

}

In the above precedent, in the wake of deallocating the memory from a pointer variable, ptr is alloted to a NULL esteem. This implies ptr does not point to any memory area. Subsequently, it is never again a dangling pointer.

What is pointer to pointer in C? 

If there should arise an occurrence of a pointer to pointer idea, one pointer alludes to the location of another pointer. The pointer to pointer is a chain of pointers. For the most part, the pointer contains the location of a variable. The pointer to pointer contains the location of a first pointer. How about we comprehend this idea through a model:

#include  

int primary()

{

int a=10;

int *ptr,**pptr;/*ptr is a pointer and **pptr is a twofold pointer.

ptr=&a;

pptr=&ptr;

printf("value of an is:%d",a);

printf("\n");

printf("value of *ptr is : %d",*ptr);

printf("\n");

printf("value of **pptr is : %d",**pptr);

return 0;

}

In the above precedent, pptr is a twofold pointer indicating the location of the ptr variable and ptr focuses to the location of 'a' variable.

What is static memory designation? 

If there should be an occurrence of static memory allotment, memory is apportioned at assemble time, and memory can't be expanded while executing the program. It is utilized in the cluster.

The lifetime of a variable in static memory is the lifetime of a program.

The static memory is assigned utilizing static catchphrase.

The static memory is executed utilizing stacks or pile.

The pointer is required to get to the variable present in the static memory.

The static memory is quicker than dynamic memory.

In static memory, more memory space is required to store the variable.

For instance:

int a[10];

The above precedent makes a variety of number sort, and the extent of an exhibit is fixed, i.e., 10.

What is dynamic memory designation? 

If there should be an occurrence of dynamic memory assignment, memory is apportioned at runtime and memory can be expanded while executing the program. It is utilized in the connected rundown.

The malloc() or calloc() work is required to dispense the memory at the runtime.

A distribution or deallocation of memory is done at the execution time of a program.

No unique pointers are required to get to the memory.

The dynamic memory is actualized utilizing information portions.

Less memory space is required to store the variable.

For instance

int *p= malloc(sizeof(int)*10);

The above model designates the memory at runtime.

What capacities are utilized for dynamic memory designation in C language? 

malloc()

The malloc() work is utilized to apportion the memory amid the execution of the program.

It doesn't introduce the memory yet conveys the refuse esteem.

It restores an invalid pointer on the off chance that it couldn't almost certainly assign the mentioned space.

Sentence structure

ptr = (cast-type*) malloc(byte-measure)/distributing the memory utilizing malloc() work.

calloc()

The calloc() is same as malloc() work, however the distinction just is that it instates the memory with zero esteem.

Sentence structure

ptr = (cast-type*)calloc(n, component estimate);//designating the memory utilizing calloc() work.

realloc()

The realloc() work is utilized to reallocate the memory to the new size.

In the event that adequate space isn't accessible in the memory, at that point the new square is assigned to oblige the current information.

Sentence structure

ptr = realloc(ptr, newsize);/refreshing the memory estimate utilizing realloc() work.

In the above sentence structure, ptr is apportioned to another size.

free():The free() work discharges the memory assigned by either calloc() or malloc() work.

Grammar

free(ptr);/memory is discharged utilizing free() work.

The above grammar discharges the memory from a pointer variable ptr.

What is the structure? 

The structure is a client characterized information type that permits putting away numerous sorts of information in a solitary unit. It possesses the whole of the memory all things considered.

The structure individuals can be gotten to just through structure factors.

Structure factors getting to a similar structure yet the memory apportioned for every factor will be extraordinary.

Linguistic structure of structure

struct structure_name

{

Member_variable1;

Member_variable2

.

.

}[structure variables];

We should see a straightforward precedent.

#include  

struct understudy

{

burn name[10];/structure individuals assertion.

int age;

}s1;/structure variable

int principle()

{

printf("Enter the name");

scanf("%s",s1.name);

printf("\n");

printf("Enter the age");

scanf("%d",&s1.age);

printf("\n");

printf("Name and age of an understudy: %s,%d",s1.name,s1.age);

return 0;

}

Yield:

Enter the name shikha

Enter the age 26

Name and age of an understudy: shikha,26



What is an association? 

The association is a client characterized information type that permits putting away numerous sorts of information in a solitary unit. In any case, it doesn't involve the whole of the memory everything being equal. It holds the memory of the biggest part as it were.

In association, we can get to just a single variable at once as it assigns one regular space for every one of the individuals from an association.

Punctuation of association

association union_name

{

Member_variable1;

Member_variable2;

.

.

Member_variable n;

}[union variables];

We should see a straightforward model

#include 

association information

{

int a;/endorsers announcement.

coast b;

singe ch;

};

int primary()

{

association information d;/association variable.

d.a=3;

d.b=5.6;

d.ch='a';

printf("value of an is %d",d.a);

printf("\n");

printf("value of b is %f",d.b);

printf("\n");

printf("value of ch is %c",d.ch);

return 0;

}

Yield:

estimation of an is 1085485921

estimation of b is 5.600022

estimation of ch is a

In the above precedent, the estimation of an and b gets debased, and just factor ch demonstrates the real yield. This is on the grounds that every one of the individuals from an association share the regular memory space. Consequently, the variable ch whose esteem is as of now refreshed.

What is an auto catchphrase in C? 

In C, each nearby factor of a capacity is known as a programmed (auto) variable. Factors which are announced inside the capacity square are known as a nearby factor. The nearby factors are otherwise called an auto variable. It is discretionary to utilize an auto watchword before the information sort of a variable. In the event that no esteem is put away in the nearby factor, at that point it comprises of a refuse esteem.

What is the reason for sprintf() work? 

The sprintf() means "string print." The sprintf() work does not print the yield on the reassure screen. It exchanges the information to the support. It restores the all out number of characters present in the string.

Language structure

int sprintf ( burn * str, const singe * group, ... );

We should see a straightforward precedent

#include 

int principle()

{

singe a[20];

int n=sprintf(a,"javaToint");

printf("value of n is %d",n);

return 0;}

Yield:

estimation of n is 9

Can we aggregate a program without principle() work? 

Indeed, we can aggregate, yet it can't be executed.

Be that as it may, in the event that we use #define, we can gather and run a C program without utilizing the principle() work. For instance:

#include 

#define begin primary

void begin() {

printf("Hello");

}

What is a token? 

The Token is an identifier. It tends to be steady, catchphrase, string strict, and so on. A token is the littlest individual unit in a program. C has the accompanying tokens:

Identifiers: Identifiers allude to the name of the factors.

Catchphrases: Keywords are the predefined words that are clarified by the compiler.

Constants: Constants are the fixed qualities that can't be changed amid the execution of a program.

Administrators: An administrator is an image that plays out the specific task.

Extraordinary characters: All the characters with the exception of letter sets and digits are treated as unique characters.
30) What is order line contention?

The contention go to the primary() work while executing the program is known as direction line contention. For instance:

main(int check, burn *args[]){

/code to be executed

}

What is the abbreviation for ANSI? 

The ANSI represents " American National Standard Institute." It is an association that keeps up the expansive scope of controls including photographic film, scripting languages, information encoding, mechanical parts, security and then some.

What is the contrast among getch() and getche()? 

The getch() work peruses a solitary character from the console. It doesn't utilize any cushion, so entered information won't be shown on the yield screen.

The getche() work peruses a solitary character from the catchphrase, however information is shown on the yield screen. Press Alt+f5 to see the entered character.

We should see a basic precedent

#include 

#include 

int primary()

{

scorch ch;

printf("Enter a character ");

ch=getch();/taking a client contribution without printing the esteem.

printf("\nvalue of ch is %c",ch);

printf("\nEnter a character again ");

ch=getche();/taking a client info and afterward showing it on the screen.

printf("\nvalue of ch is %c",ch);

return 0;

}

Yield:

Enter a character

estimation of ch is a

Enter a character again a

estimation of ch is a

In the above precedent, the esteem entered through a getch() work isn't shown on the screen while the esteem entered through a getche() work is shown on the screen.

What is the newline escape grouping? 

The new line escape succession is spoken to by "\n". It embeds another line on the yield screen.

Who is the fundamental giver in structuring the C language after Dennis Ritchie? 

Cerebrum Kernighan.

What is the distinction between close, far and tremendous pointers? 

A virtual location is made out of the selector and counterbalance.

A close pointer doesn't have unequivocal selector though far, and tremendous pointers have express selector. When you perform pointer number juggling on the far pointer, the selector isn't adjusted, yet in the event of a colossal pointer, it tends to be altered.

These are the non-standard watchwords and execution explicit. These are unessential in a cutting edge stage.

What is the greatest length of an identifier? 

It is 32 characters preferably yet usage explicit.

What is pigeonholing? 

The pigeonholing is a procedure of changing over one information type into another is known as pigeonholing. On the off chance that we need to store the drifting kind incentive to an int type, at that point we will change over the information type into another information type unequivocally.

Grammar

(type_name) articulation;

What are the capacities to open and close the record in C language? 

The fopen() work is utilized to open document though fclose() is utilized to close record.

Can we get to the exhibit utilizing a pointer in C language? 

Truly, by holding the base location of cluster into a pointer, we can get to the exhibit utilizing a pointer.

What is a boundless circle? 

A circle running constantly for an uncertain number of times is known as the endless circle.

Unending For Loop:

for(;;){

/code to be executed

}

Unending While Loop:

while(1){

/code to be executed

}

Unending Do-While Loop:

do{

/code to be executed

}while(1);

41) Write a program to print "hi world" without utilizing a semicolon?

#include 

void main(){

if(printf("hello world")){}/It prints the ?welcome world? on the screen.

}


Write a program to swap two numbers without utilizing the third factor? 

#include 

#include 

fundamental()

{

int a=10, b=20;/revelation of factors.

clrscr();/It clears the screen.

printf("Before swap a=%d b=%d",a,b);

a=a+b;//a=30 (10+20)

b=a-b;//b=10 (30-20)

a=a-b;//a=20 (30-10)

printf("\nAfter swap a=%d b=%d",a,b);

getch();

}


Write a program to print Fibonacci arrangement without utilizing recursion? 

#include 

#include 

void primary()

{

int n1=0,n2=1,n3,i,number;

clrscr();

printf("Enter the quantity of elements:");

scanf("%d",&number);

printf("\n%d %d",n1,n2);//printing 0 and 1

for(i=2;i
{

n3=n1+n2;

printf(" %d",n3);

n1=n2;

n2=n3;

}

getch();



Write a program to print Fibonacci arrangement utilizing recursion? 

#include 

#include 

void printFibonacci(int n)/capacity to figure the fibonacci arrangement of a given number.

{

static int n1=0,n2=1,n3;/announcement of static factors.

if(n>0){

n3 = n1 + n2;

n1 = n2;

n2 = n3;

printf("%d ",n3);

printFibonacci(n-1);/calling the capacity recursively.

}

}

void main(){

int n;

clrscr();

printf("Enter the quantity of components: ");

scanf("%d",&n);

printf("Fibonacci Series: ");

printf("%d %d ",0,1);

printFibonacci(n-2);//n-2 since 2 numbers are as of now printed

getch();

}

Write a program to check prime number in C Programming? 

#include 

#include 

void principle()

{

int n,i,m=0,flag=0;/assertion of factors.

clrscr();/It clears the screen.

printf("Enter the number to check prime:");

scanf("%d",&n);

m=n/2;

for(i=2;i<=m;i++)

{

if(n%i==0)

{

printf("Number isn't prime");

flag=1;

break;/break catchphrase used to end from the circle.

}

}

if(flag==0)

printf("Number is prime");

getch();/It peruses a character from the catchphrase.

}
46) Write a program to check palindrome number in C Programming?

#include 

#include 

fundamental()

{

int n,r,sum=0,temp;

clrscr();

printf("enter the number=");

scanf("%d",&n);

temp=n;

while(n>0)

{

r=n%10;

sum=(sum*10)+r;

n=n/10;

}

if(temp==sum)

printf("palindrome number ");

else

printf("not palindrome");

getch();

}

Write a program to print factorial of given number without utilizing recursion? 

#include 

#include 

void main(){

int i,fact=1,number;

clrscr();

printf("Enter a number: ");

scanf("%d",&number);

for(i=1;i<=number;i++){

fact=fact*i;

}

printf("Factorial of %d is: %d",number,fact);

getch();

}

48) Write a program to print factorial of given number utilizing recursion?

#include 

#include 

long factorial(int n)/capacity to compute the factorial of a given number.

{

on the off chance that (n == 0)

return 1;

else

return(n * factorial(n-1));/calling the capacity recursively.

}

void principle()

{

int number;/assertion of factors.

long reality;

clrscr();

printf("Enter a number: ");

scanf("%d", &number);

reality = factorial(number);/calling a capacity.

printf("Factorial of %d is %ld\n", number, reality);

getch();/It peruses a character from the catchphrase.

}

49) Write a program to check Armstrong number in C?

#include 

#include 

primary()

{

int n,r,sum=0,temp;/announcement of factors.

clrscr();/It clears the screen.

printf("enter the number=");

scanf("%d",&n);

temp=n;

while(n>0)

{

r=n%10;

sum=sum+(r*r*r);

n=n/10;

}

if(temp==sum)

printf("armstrong number ");

else

printf("not armstrong number");

getch();/It peruses a character from the catchphrase.

} .

Write a program to turn around a given number in C? 

#include 

#include 

primary()

{

int n, reverse=0, rem;/statement of factors.

clrscr();/It clears the screen.

printf("Enter a number: ");

scanf("%d", &n);

while(n!=0)

{

rem=n%10;

reverse=reverse*10+rem;

n/=10;

}

printf("Reversed Number: %d",reverse);

getch();/It peruses a character from the catchphrase.

}