0% found this document useful (0 votes)
0 views14 pages

c Programming Interview2

Uploaded by

Nagesh Kumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
0 views14 pages

c Programming Interview2

Uploaded by

Nagesh Kumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 14

Top 40 Most asked C Interview Questions &

Answers (Freshers)

C programming interview questions are a part of most technical rounds


conducted by employers. The main goal of questioning a candidate on C
programming is to check his/her knowledge about programming and core
concepts of the C language. In this article, you will find a mix of C language
interview questions designed specially to give you a foundation and build on it.
1.Why is C called a mid-level programming language?
C possesses features of both lower-level and higher-level, or assembly-level,
languages. C is hence frequently referred to be a middle-level language. One
may write both a menu-driven consumer billing system and an operating system
in C.

2.What are the features of the C language?


Middle-level language: Provides low-level memory access and high-level
abstractions, balancing efficiency and ease of use.
Portability: Code written in C can run on different platforms with minimal
modifications.
Efficiency: Offers efficient memory management and execution speed.
Roch Standard Library: Provides a comprehensive set of functions for various
tasks.
Procedural Language: Follows a structured, step-by-step approach to solving
problems.

3.What is a token?
Tokens are the discrete components of a program. There are 6 tokens in C
language, those are-

● Identifiers
● Keywords
● Constants
● Operators
● Special Characters
4.What is the use of printf() and scanf() functions? Also, explain format
specifiers?
Printf()- To print the output to the screen, use print().

Scanf()- To read formatted data from the keyboard, use scanf().

The following are a few datatype format specifiers that can be used for scanning
and printing:
%d- It's a format specifier for datatypes that prints and scans integer values.
%s- This datatype format specifier is used to print and scan strings in the
program.
%c- It is a format specifier for a datatype that is used to display and scan
character values.
%f- The float value may be seen and scanned using the datatype format
specifier %f.

5.What's the value of the expression 5["zyzuv"]?


The answer is "f". In C-style languages, the expression 5["zyzuv"] is equivalent
to "zyzuv"[5], which accesses the 6th character of the string "zyzuv". Therefore,
the value of the expression is "v".

6.What are basic data types supported in the C Programming Language?


In C programming, basic data types include:

Primitive Data type- There are two other categories of primitive data types:
integer and floating.
User-Defined data types- The user defines these data types to improve
program readability.
Derived data types- Data types that come from pre-built or basic data types.
7.What is a built-in function in C?
The built-in C functions scanf(), printf(), strcpy, strlwr, strcmp, strlen, strcat, and
many more are used often.

The term "built-function" refers to library functions that the system provides to
developers to help them with specific frequently performed predefined tasks,
hence simplifying their lives. For instance, printf() in C is used when you need to
print your program's output to the terminal.

8.What do you mean by the scope of the variable?


In programming languages, scope refers to the block or region where a specified
variable will live; if the variable extends outside of that block or region, it will be
immediately destroyed. Every variable has a certain range of use. To put it
simply, a variable's scope is determined by how long it remains in the program.
Three different places can define the variable. They are as follows:

Local Variables: Located within a certain block or function


Global Variables: Among all the functions that the program does globally.
Formal parameters:These are limited to in-function parameters.

9.What is a Preprocessor?
A software application known as a preprocessor is used to handle source files
before submitting them to be built. The preprocessor allows for the inclusion of
header files, macro expansions, conditional compilation, and line control.
10.What are preprocessor directives in C?
Preprocessor directives in C are built-in predefined functions or macros that are
performed before program execution and serve as instructions to the compiler.
The process of creating and running a C program involves several phases.
Macros, File Inclusion, Conditional Compilation, and Other directives like #undef,
#pragma, etc. are the main categories of Preprocessor Directives.

11.What is the difference between malloc() and calloc() in the C


programming language?
The library methods malloc() and calloc() are used to allocate dynamic memory.
The memory that is allocated from the heap section while the program is
running is known as dynamic memory. The header file "stdlib.h" is what makes
dynamic memory allocation in the C programming language possible.

Parameter Malloc() Calloc()

Definition It is a function that It is a function that


generates a single, allows a single variable
fixed-size memory block. to be assigned to several
memory blocks.

Number of arguments One argument is all that There must be two


is needed. arguments.

Speed Calloc() is slower than Compared to malloc(),


the malloc() procedure. calloc() is slower.

Efficiency It is quite efficient with It is not very


time time-efficient.

Usage It serves as a memory It serves as a signal for


allocation indicator. contiguous memory
allocation.
12.What is a Pointer in C?
A pointer in C is a variable that holds the memory address of another variable. It
allows direct manipulation of memory locations, enabling dynamic memory
allocation, efficient array handling, and indirect access to data. Pointers are a
fundamental feature used for tasks like data structures and dynamic memory
management.

16.Define Loops in C language. What are the types of loops in C?


Loops in C are programming constructs that repeatedly execute a block of code
as long as a specified condition is true. They enable efficient iteration through
data, simplifying tasks like array manipulation or repetitive operations, ensuring
code efficiency and maintainability. Common loop types in C include for, while,
and do-while.

17.What are header files in C and their uses?


In C programming, header files are files containing function declarations and
macro definitions. They allow code reuse by providing function prototypes to
other source files. Commonly used header files include <stdio.h> for
input/output functions and <stdlib.h> for memory allocation functions.
18.What is the difference between macro and functions?
A pre-processor command that designates a group of C statements is called a
macro. The pre-processor directive defines a macro. Since macros are
preprocessed, our program would not have been compiled until after all of the
macros had been preprocessed. Functions are compiled rather than
preprocessed, though.

Macro Function

Preprocessed macros are used. The functions are compiled.

Using a macro, the code length is Using a function does not affect code
enhanced. length.

With a macro, execution speed is Using a function results in reduced


increased. execution speed

The macro name is replaced by the Control is transferred during the


macro value before compilation function call.

19.Specify different types of decision control statements in C


A program executes each sentence one at a time, starting at the top and
working down. Depending on the circumstance, control statements are used to
execute or move control from one area of the program to another. The different
types of control statements are:
● Simple if statement
● if...else statement
● if else...if ladder
● nested if...else statement
● Switch statement.
20.How to convert a String to Numbers in C?
There are two primary techniques in C for converting strings to numbers: string
streams and the stoi() and atoi() library functions.
sscanf()-Instead of using normal input, it reads data from a string.
atoi()-This method returns an integer value when it receives a character array or
a string literal as input.

21.What are Reserved Keywords in C?


In a program, each keyword is designed to carry out a certain function. They
cannot be used for reasons other than those for which they were designed since
their meaning has already been established. The programming language C has
32 keywords supported. Reserved keywords include things like auto, else, if,
long, int, switch, typedef, and so on.

22.Explain Modifiers in C
In the C language, modifiers are keywords that are used to alter the meaning of
fundamental data types. They outline how much memory should be set aside
for the variable. There are five types of modifiers, which are
● long
● short
● signed
● unsinged
● long long
23.What is the difference between #include "..." and #include <...>?
In C programming, both #include "..." and #include <...> are used to include
header files, but they differ in their search paths and usage:
#include "..." (Double Quotes): The C preprocessor searches the predefined list
of system directories for the filename before checking user-specified directories
(directories can be added to the predefined list by using the -I option).
#include <...> (Angle Brackets): The preprocessor follows the search path
given for the #include <filename> form after first searching in the same directory
as the file containing the directive. Include programmer-defined header files
using this way.
Using double quotes ("...") is generally preferred for including project-specific
headers, while angle brackets (<...>) are used for standard library or system
headers to distinguish between user-defined and system-provided header files.

24.What is the use of an extern storage specifier?


In the C language, the extern keyword is used to increase the visibility of C
variables and functions. External can be shortened to extern. When a specific
file wants to access a variable from any other file, it is used. Variables containing
the extern keyword are simply declared, not defined, which increases
duplication. There is no need to declare or create extern functions because they
are visible by default throughout the program.
25.What is the difference between getc(), getchar(), getch() and getche() in
C?
getc():Reads a character from the specified file stream (e.g., stdin, file).
Requires stdio.h header.
Offers flexibility for reading from different input sources.
getchar():Reads a character from the standard input stream (stdin).
Requires stdio.h header.
Commonly used for simple character input from the keyboard.
getch():Reads a character from the keyboard without echoing it to the screen.
Typically used in older MS-DOS and Windows environments.
Requires conio.h header (non-standard and not portable).
getche():Reads a character from the keyboard and echoes it to the screen.
Similar to getch(), but it displays the input character.
Requires conio.h header (non-standard and not portable).
Note: getch() and getche() are not standard C functions and are not
recommended for portable and modern C programming. Prefer using getc() or
getchar() for standard and portable input operations.

26.How is import in Java different from #include in C?


Import is a keyword, but #include is a statement processed by pre-processor
software. #include increases in the size of the code.

Related Interview Articles:


● C++ interview questions
● C# interview questions
● Java interview questions
● Javascript Interview Questions
● JQuery Interview Questions
27.What is the function of s++ and ++s?
s++ is a single machine instruction used to increment the value of s by 1. (Post
increment). ++s is used to carry out pre-increment.

28.Define <stdio.h>.
It is a header file in C that contains prototypes and definitions of commands such
as scanf and printf.[2] [MOU3]

29.One of the most common c language interview questions is to define the


What is the use of static functions.?
When we want to restrict access to functions, we need to make them static.
Making functions static allows us to reuse the same function in C programming
name in multiple files.

30.Name the four categories in which data types in the C programming


language are divided in.
Basic data types - Arithmetic data types, further divided into integer and
floating-point types
Derived datatypes -Arithmetic data types that define variables and assign
discrete integer values only
Void data types - no value is available
Enumerated data types -Array types, pointer types, function, structure and union
types
31.What is the use of the ‘==’ symbol?
The ‘==’ symbol or “equivalent to” or “equal to” symbol is a relational operator,
i.e., it is used to compare two values or variables.

32.Mention some of the features of the C programming language.


Some of the feature are:
Middle-Level Language - Combined form of both high level language and
assembly language
Pointers - Supports pointers
Extensible - Easy to add features to already written program
Recursion - Supports recursion making programs faster
Structured Language - It is a procedural and general purpose language.

33.Why is int known as a reserved word?


As int is a part of standard C language library, and it is not possible to use it for
any other activity except its intended functionality, it is known as a reserved
word.

34.Another frequent c interview question is what is meant by Call by


reference?
When a variable’s value is sent as a parameter to a function, it is known as call
by reference. The process can alter the value of the variable within the function.
35.What information is given to the compiler while declaring a prototype
function?
The following information is given while declaring a prototype function:

● Name of the function


● Parameters list of the function
● Return type of the function.[6]

36.What is a union?
A union is a data type used to store different types of data at the exact memory
location. Only one member of a union is helpful at any given time.

37.How is import in Java different from #include in C?


Import is a keyword, but #include is a statement processed by pre-processor
software. #include increases the size of the code.

38.What is the stack area?


The stack area is used to store arguments and local variables of a method. It
stays in memory until the particular method is not terminated.

39.What are huge pointers?


Huge pointers are 32-bit pointers that can be accessed outside the segment,
and the segment part can be modified, unlike far pointers.
40.Name a type of entry controlled and exit controlled loop in C
programming.
Entry controlled loop- For loop (The condition is checked at the beginning)
Exit Controlled loop- do-while loop.[7] (The condition is checked in the end, i.e.
loop runs at least once)

Good luck!

You might also like