Dj Techblog

A blog on web development

Most frequently asked C interview questions

Last modified on June 05, 2022

Below are the list of most frequently asked interview questons related to C programming. It almost covered all the topic. Beautifully explained with suitable short examples that helps you in basic understanding of C programming.

What is the use of getch() in C program?

Answer: The getch() is a predefined function in C language which is declared in conio.h header file. The getch() function is generally used at the end of The C program to make the program output wait for user to see the required result. In the absence of getch() function the program will not display the console screen and will return to Turbo C editor quickly.

So, basically what it does, it pauses the program output until user doesn't enters a key. When we use this function at the end of the program, the function makes the program wait until a key is entered by the user. Once, the user enters the, the program returns to the editor screen.

The return type of getch() function is integer. It returns the ASCII value of the character that is entered by the user.

We can understand the above properties of getch() function by the following C program.

                  
    #include<stdio.h>
    #include<conio.h>
    void main()
    {
    	int x = getch();
    	printf("X= %d",x);
    	getch();
    }
              

Now run the program in turbo c++ editor, and enter any character. You will see the ASCII value of the character returned by the Compiler. say I type a, it will retyurn value of a, that is 97. If I type A, ut will return 65.

What is the return type of printf() function in C?

Answer: The return type of printf() function is integer. and it returns the number of characters it has printed on the console.

Where does printf() function is declared in C?

The printf() function is declared in stdio.h header file. It is a predefined formatted funtion.

Where does scanf() function is declared in C?

The scanf() function is declared in stdio.h header file. It is a predefined funtion.

printf() vs scanf()

Sl No. printf() scanf()
1 Its is a standard function defined in stdio.h header file It is also a standard function defined in stdio.h header file.
2 It returns the number of value it has printed to the console. It returns the number of characters it has scanned from the console.
3 It sends formatted output to the stdin It gets formatted output from the stdin.
4 Function definition int printf(const char *format [, argument,...] ) Function definition int scanf(const char *format [, address,...] )

What is the difference between getch() and getchar() ?

Sl No. getch() getchar()
1 It is a non-buffered function It is not a function but a macro and it is buffered.
2 It returns the value as soon as it reads. It returns the value only after user hits Enter.
3 It is defined in conio.h header file. It is defined in stdio.h header file.
4 It has only one variant. It has two variant getchar() and fgetchar().
5 Function definition int getch(void) Function definition int getchar(void)

What is the difference between getch() vs getche() ?

Getch() and Getche() has more similarities between them. Both are functions defined in conio.h header file and returns the ASCII value of the character entered in the integer format. Their function definition are int getch() and int getche(). Getch() and Getche(), both are non buffred function, that is it retuns the character as soon as entered, the user doesn't have to press Enter key. One more similarity between them is both reads from Standard Input Stream only. The only dfference between them is mentioned below.
Sl No. getch() getche()
1 It does not echo to the screen. It echoes the character entered to the screen.

What is the difference between getchar() and scanf() ?

Sl No. scanf() getchar()
1 It is formatted function which can take keystrokes in any format like int, char, float, double etc. It is not a formatted function but a macro, it only reads character from stdin.
2 It returns the number of values has been scanned. It returns the integer value of character has been read.
3 It can accept more than one values from stdin at a time. It can accept only one value at a time.
4 Function definition int scanf(const char *format [, address,...] ) Function definition int getchar(stdin)

What is the difference between getc() and scanf() ?

Sl No. scanf() getc()
1 It is formatted function which can take keystrokes in any format like int, char, float, double etc. It is not a function but a macro, it only reads character from stdin that it can not differentiate between int, char, double etc.
2 It returns the number of values has been scanned. It returns the integer value of next character has been read from input stream.
3 It accepts input only from Standard Input Stream. It accepts input from Standard Input Stream as well as File Input Stream.
4 It scans until user hits Enter. It reads until an error or EOF(End of File) has been reached.
5 Function definition int scanf(const char *format [, address,...] ) Function definition int getc(FILE *stream)

Dangling Pointer vs Null Pointer vs void Pointer vs Pointer to pointer

Dangling Pointer

If the memory location pointed by a pointer variable is deleted then the pointer variable becomes a dangling pointer.

Null Pointer

If the pointer variable is not initiailized to any memory location then it is called a Null pointer. In scuh case it does not point to any memory location.

 int *x;      // Here x is a null pointer, because it doesn't point to any memory location.

Void Pointer

A pointer variable can be of type void, then it is called void pointer. It can keep address of any kind of variable type whether it is int, char, float or double. Generally, a specific type of pointer variable say integer pointer can keep address of only integer variable but such is the not the case with void pointer. It can point to any type of variable type.

 void *x;      // Here x is a void pointer and it can store address of any kind of variable.

Pointer to pointer variable

A pointer to pointer variable is also a kind of pointer variable which can point to another pointer variable. The way it differs from pointer is pointer stores the address of normal variable but pointer to pointer stores the address of any other pointer variable. Like pointer, it also points to a specific type of pointer so an integer pointer to pointer can point to an interger pointer variable only.

 void **x;      // Here x is a pointer to pointer and it can store address of any other pointer variable

Published on Oct 20, 2021


Ad section

Intro

Debabratta Jena

I mainly write about HTML5, CSS3, Javascript, Angular JS, Ajax, PHP, Mysql, On page SEO, Google Ads, Tag manager, Universal Analytics, Google My Business, SERP, Apache server configuration etc, Yoga is my passion.

Reach to me in the contact us form below

Follow me on

Contact us

Subscribe

Tags

C C++ Javascript CSS Java Btech Interview questions Programming

Ad section
×

Subscribe to get email notification about our new post

Name

Email

We neither sell nor share your personal information with any third party. Your identity is safe with us.