SlideShare a Scribd company logo
1 of 10
Download to read offline
www.login360.in
+91-63 85 87 28 10
enquiry@login360.in
1
Interview Questions For C Language
1. What is C programming language?
Ans: C is a widely used, simple-to-learn, and flexible general-purpose programming
language. This structured programming language may be used to construct a wide range of
software, including more complex ones like the Python interpreter, the Git repository, the
Oracle database, and others, as well as operating systems like Windows.
2. What are the basic data types in C?
Ans: In C, there are four fundamental data types: double floating-point, floating-point,
characters, and integers. These data types are used in C programmes to specify variables
and functions.
1. Integer: Integers are used to represent whole numbers. Copies may or may not have a
signature. To declare integer variables, use the "int" keyword.
2. Character: Single characters, such as letters, numerals, and symbols, are represented by
characters. They are declared using the "char" keyword.
3. Floating-point: Float-point data types are used to represent actual numbers with decimal
points. Either single precision or double precision is possible. Declaring floating-point
variables requires the use of the "float" and "double" keywords.
4. Double floating-point: Double floating-point data types more accurately reflect actual
numbers when compared to floating-point data types.
For example,
int x = 10;
char c = 'A';
float f = 3.14;
double d = 3.14159;
3.What is a constant and how is it declared in C?
Ans: A constant is a value in a program that cannot be changed during its execution. In C,
constants are declared using the "const" keyword. Once a constant is defined, its value
cannot be changed throughout the program's execution. Constants can be used in place of
literal values to make code more readable and maintainable.
The syntax for declaring a constant in C is as follows: const data_type constant_name =
value;
4. What are the different types of operators in C?
Ans: Operators in the C programming language are symbols that denote specific actions to
be taken on operands (variables, constants, or expressions). In C, there are several kinds of
operators, such as:
www.login360.in
+91-63 85 87 28 10
enquiry@login360.in
2
1. Arithmetic Operators: Used for addition, subtraction, multiplication, division, and modulus
operations.
Examples include plus (+), minus (-), * (multiplication), / (division), and % (modulus).
2. Relational Operators: These are used to compare two values and return either true or
false as a boolean value.
For instance,!= (not equal), == (equality), (less than), > (greater than), = (less than or equal
to), and >= (greater than or equal to)
3. Logical Operators: These are used to combine two or more relational expressions and
return a boolean (true or false) value.
Example:! (logical not), || (logical either), and && (logical and).
4. Bitwise Operators: These are used to perform bitwise operations at the bit level on two
operands.
Example: & (bitwise and), | (bitwise or), ^ (bitwise exclusive or), ~ (bitwise complement), <<
(left shift), >> (right shift)
5. Assignment operators : Are employed to simultaneously assign a value to a variable and
carry out an action.
Example: = (simple assignment), += (add and assign), -= (subtract and assign), *= (multiply
and assign), /= (divide and assign), %= (modulus and assign), <<= (left shift and assign),
>>= (right shift and assign), &= (bitwise and and assign), |= (bitwise or and assign), ^=
(bitwise exclusive or and assign)
6. Use a Conditional operation dependent on the outcome of a boolean expression by using
a conditional operator.
Example: ?: (conditional operator)
7. Sizeof Operator: Used to calculate a data type or variable's size in bytes.
1. Example: sizeof(int), sizeof(char), sizeof(float)
8. Address and Pointer Operators: Used to manipulate memory addresses and pointers.
1. Example: & (address of), * (pointer to)
These operators can be used in numerous ways to produce complicated expressions that
carry out various actions in a C program.
5. What is a conditional statement in C?
Ans: In C programming, conditional statements are employed to base decisions on the
circumstances. In C, conditional statements are processed sequentially if there is no
condition around them. If a condition is added to a block of statements, the execution flow
may change depending on how the condition is evaluated. In "C", this procedure is known as
decision-making.
The following two structures in C can be used to create conditional statements:
 If statement
 If-else statement
www.login360.in
+91-63 85 87 28 10
enquiry@login360.in
3
6. What is a loop in C?
Ans: A loop is a programming technique that enables the repeated execution of a block of
code depending on certain circumstances. C supports "while" loops, "do-while" loops, and
"for" loops as its three different forms of loops.
 The "while" loop executes the block of code as long as a certain condition is true.
 The "do-while" loop executes the block of code at least once, and then repeatedly as
long as a certain condition is true.
 The "for" loop executes the block of code a certain number of times, based on an
initialization, condition, and update statement.
Loops are useful in situations where the same code needs to be executed multiple times
with different values. They help to reduce code duplication and improve code efficiency.
7. What is a header file in C and how is it used?
Ans : The term "header file" refers to a file with the extension ".h" that includes shared C
function declarations and macro definitions. There are two different kinds of header files:
those created by the programmer and those provided by the compiler.
For example, if you want to use the "printf" function in your C program, you would include the
"stdio.h" header file which contains the prototype for the "printf" function:
#include <stdio.h>
int main() {
printf("Hello, world!n");
return 0;
}
The "#include" directive instructs the C preprocessor to copy the contents of the "stdio.h" file
into your source file before compilation. This allows you to use the functions and
declarations in the header file without having to rewrite them in your source code.
8. What is a structure in C and how is it declared?
Ans: A user-defined data type called a structure enables you to unify variables of various
data kinds under a single name. In C, a structure is declared by using the "struct" keyword,
the structure's name, and a set of braces that enclose the variables that make up the
structure.
A structure is declared in C using the following syntax:
struct structure_name {
data_type1 variable_name1;
data_type2 variable_name2;
...
data_typen variable_namen;
};
Here, "structure_name" is the name of the structure, and "variable_name1" through
"variable_namen" are the names of the variables that make up the structure. The variables
can be of any data type, including other structures.
www.login360.in
+91-63 85 87 28 10
enquiry@login360.in
4
Once a structure is declared, you can create variables of that structure type and access the
variables inside the structure using the dot (".") operator.
9. What are the different data types in C language?
Ans: The different data types in C language are int, char, float, double, and void.
1. int - used to represent integer values
2. float - used to represent floating-point values with single precision
3. double - used to represent floating-point values with double precision
4. char - used to represent a single character or an integer value that corresponds to a
character in the ASCII table.
In addition to these basic data types, C also provides the following derived data types:
1. Arrays - used to store a collection of values of the same data type
2. Pointers - used to store memory addresses of variables
3. Structures - used to group together variables of different data types under a single
name
4. Unions - used to allocate memory for multiple variables of different data types but
only one variable can be accessed at a time
5. Enumerations - used to define a set of named constants.
10. What is a function in C language?
Ans: A function in C language is a block of code that performs a specific task and can be
called from anywhere in the program (e.g. int add(int x, int y) { return x + y; }).
11. What is a string in C and how is it declared?
Ans: In C, a string is a sequence of characters stored in consecutive memory locations. To
declare a string, you can use the character array data type, where each element of the array
represents a character in the string, and the last element is the null terminator '0'. Here's an
example of declaring a string in C:
Example:
char myString[] = "Hello, World!";
Here, `myString` is an array of characters that contains the string "Hello, World!". Note that
the null terminator is automatically added to the end of the string.
12. Why is C called a mid-level programming language?
Ans: C is called a mid-level programming language because it has features of both low-level
and high-level programming languages. It provides low-level access to memory through
www.login360.in
+91-63 85 87 28 10
enquiry@login360.in
5
pointers and high-level abstractions such as functions, control structures, and data types.
This makes it suitable for writing both system-level and application-level software.
13. What is the use of printf() and scanf() functions? Also explain format specifiers?
Ans: The `printf()` function is used for displaying output to the console or other output
devices. The `scanf()` function is used for reading input from the console or other input
devices. Format specifiers are special codes used in formatted input and output functions to
indicate the type of data being read or written. They are preceded by a `%` symbol in the
format string.
To specify the type of data being read or written, format specifiers are codes used in C's
formatted input and output functions. They instruct the function on the expected kind of data
and the formatting to be used when it is displayed or written.
The most common format specifiers are:
 %d: for integer values
 %f: for floating-point values
 %c: for characters
 %s: for strings
 %p: for pointer values
 %o: for octal values
 %x or %X: for hexadecimal values
14. What is a Preprocessor?
 The preprocessor is a component of the C compiler that processes the source code
before it is compiled.
 It performs a set of operations on the code, such as macro expansion, file inclusion,
and conditional compilation.
 The preprocessor is invoked by special commands called preprocessor directives,
which begin with a hash symbol (#).
 The most commonly used preprocessor directives are #define, #include, and #ifdef.
 The #define directive is used to create a macro, which is a symbolic name that is
replaced with a corresponding value in the code.
 The #include directive is used to include a header file in the code.
 The #ifdef directive is used to check if a certain macro is defined, and conditionally
include or exclude code based on its value.
15. What is a pointer in C?
Ans: A pointer in C is a variable that stores the memory address of another variable. It is
declared using the `*` symbol, and can be used to indirectly access and manipulate the
values stored in memory locations.
Here's a example of using a pointer to assign a value to a variable in C:
```
#include <stdio.h>
int main() {
int x = 5;
www.login360.in
+91-63 85 87 28 10
enquiry@login360.in
6
int *ptr;
ptr = &x;
*ptr = 10;
printf("The value of x is %dn", x);
return 0;
}
```
In this example, we declare an integer variable `x` and set its initial value to `5`. We also
declare an integer pointer `ptr`, and assign it the memory address of `x` using the `&`
operator. We then use the `*` operator to dereference `ptr` and assign the value `10` to the
memory location pointed to by `ptr`. This effectively changes the value of `x` to `10`. Finally,
we use `printf()` to print the updated value of `x`.
16. What is typecasting in C?
Ans: The process of changing a variable's datatype is known as typecasting. We must
explicitly transform the data type into another data type if we wish to save a huge type value
as an int type.
Syntax: (data_type)expression;
For Example:
int x;
for(x=97; x<=122; x++)
{
printf("%c", (char)x); /*Explicit casting from int to char*/
}
17. What is recursion in C?
Ans: Recursion occurs when a C function calls a duplicate of itself. To put it another way,
this method is known as recursion when a function calls itself. This function is also referred
to as a recursive function.
Syntax of Recursive Function:
void do_recursion()
{
... .. ...
do_recursion();
... .. ...]
}
int main()
{
... .. ...
do_recursion();
... .. ...
}
18. Why doesn’t C support function overloading?
www.login360.in
+91-63 85 87 28 10
enquiry@login360.in
7
Function overloading is not supported by C since it is unable to differentiate between
functions based on their signatures (parameter types and number of arguments). If you
attempt to declare more than one function with the same name in C, a compilation error will
take place. Each function has to be given a unique name.
For example, the following code is not allowed in C:
```
int add(int a, int b) {
return a + b;
}
float add(float a, float b) {
return a + b;
}
```
Because C++ supports function signature differentiation, which enables functions with the
same name to be distinguished based on their parameter types and/or a number of
parameters, function overloading is possible.
19. What are Enumerations?
Ans: Enumerations in C are user-defined data types used to assign names to integer
constants, making it easier to read and maintain code. An enumeration consists of a set of
named integer constants, known as enumerators or members, which are typically used to
represent a finite set of values for a given variable.
For Example:
#include <stdio.h>
enum Days {Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday};
int main() {
enum Days today = Wednesday;
printf("Today is %dn", today); // Output: Today is 2
return 0;
}
In this example, we declare an enumeration called `Days` that has seven possible values -
`Monday`, `Tuesday`, `Wednesday`, `Thursday`, `Friday`, `Saturday`, and `Sunday`. We
then declare a variable called `today` of type `Days` and assign it the value `Wednesday`.
We then print out the value of `today`, which is `2` because `Wednesday` is the third value in
the enumeration (counting from `0`).
20. What is the difference between global int and static int declaration?
Ans: The main difference between a global `int` and a `static int` declared inside a function is
their scope and lifetime.
www.login360.in
+91-63 85 87 28 10
enquiry@login360.in
8
A global `int` variable is declared outside of any function and has a global scope, which
means it can be accessed by any function in the program. It also has a lifetime that lasts for
the entire duration of the program.
On the other hand, a `static int` variable declared inside a function has a local scope, which
means it can only be accessed by that function. However, it has a lifetime that lasts for the
entire duration of the program, just like a global variable. Additionally, a `static int` variable
retains its value between function calls, whereas a regular local variable would be re-
initialized each time the function is called.
In summary, a global `int` variable can be accessed by any function in the program, whereas
a `static int` variable declared inside a function is limited to that function's scope, but retains
its value between function calls.
21. What is the difference between a structure and a union in C?
In C, a structure is a user-defined composite data type that groups together related data of
different data types under a single name. A union, on the other hand, is also a user-defined
composite data type that allows storing different data types in the same memory location at
different times.
The main difference between a structure and a union is in the way they store and access
data. In a structure, each member variable has its own memory location, while in a union, all
members share the same memory location. This means that modifying one member of a
union will change the value of all other members as well. Additionally, the size of a union is
determined by the size of its largest member, while the size of a structure is the sum of the
sizes of all its members.
For examples:
1. Example of a structure in C:
```
struct person {
char name[50];
int age;
float salary;
};
int main() {
struct person p1; // Declaring a variable of type struct person
// Assigning values to the members of the structure
strcpy(p1.name, "John");
p1.age = 25;
p1.salary = 5000.0;
// Accessing the members of the structure
printf("Name: %sn", p1.name);
printf("Age: %dn", p1.age);
printf("Salary: %.2fn", p1.salary);
www.login360.in
+91-63 85 87 28 10
enquiry@login360.in
9
return 0;
}
```
2. Example of a union in C:
```
union data {
int i;
float f;
char c;
};
int main() {
union data d; // Declaring a variable of type union data
d.i = 10; // Assigning a value to the integer member
printf("i = %dn", d.i);
d.f = 3.14; // Assigning a value to the float member
printf("f = %.2fn", d.f);
d.c = 'a'; // Assigning a value to the character member
printf("c = %cn", d.c);
return 0;
}
www.login360.in
+91-63 85 87 28 10
enquiry@login360.in
10
Enquiry Now
www.login360.in
+91-63 85 87 28 10
enquiry@login360.in

More Related Content

Similar to C Language Interview Questions: Data Types, Pointers, Data Structures, Memory Management

Similar to C Language Interview Questions: Data Types, Pointers, Data Structures, Memory Management (20)

C language ppt
C language pptC language ppt
C language ppt
 
C presentation! BATRA COMPUTER CENTRE
C presentation! BATRA  COMPUTER  CENTRE C presentation! BATRA  COMPUTER  CENTRE
C presentation! BATRA COMPUTER CENTRE
 
C language
C languageC language
C language
 
C Programming Unit-1
C Programming Unit-1C Programming Unit-1
C Programming Unit-1
 
C material
C materialC material
C material
 
Pc module1
Pc module1Pc module1
Pc module1
 
PSPC--UNIT-2.pdf
PSPC--UNIT-2.pdfPSPC--UNIT-2.pdf
PSPC--UNIT-2.pdf
 
C programming basic concepts of mahi.pptx
C programming basic concepts of mahi.pptxC programming basic concepts of mahi.pptx
C programming basic concepts of mahi.pptx
 
Fundamentals of c language
Fundamentals of c languageFundamentals of c language
Fundamentals of c language
 
Structures
StructuresStructures
Structures
 
Basic Concepts of C Language.pptx
Basic Concepts of C Language.pptxBasic Concepts of C Language.pptx
Basic Concepts of C Language.pptx
 
history of c.ppt
history of c.ppthistory of c.ppt
history of c.ppt
 
C notes
C notesC notes
C notes
 
Introduction%20C.pptx
Introduction%20C.pptxIntroduction%20C.pptx
Introduction%20C.pptx
 
5 introduction-to-c
5 introduction-to-c5 introduction-to-c
5 introduction-to-c
 
unit 1 cpds.pptx
unit 1 cpds.pptxunit 1 cpds.pptx
unit 1 cpds.pptx
 
Programming construction tools
Programming construction toolsProgramming construction tools
Programming construction tools
 
unit2.pptx
unit2.pptxunit2.pptx
unit2.pptx
 
C intro
C introC intro
C intro
 
Data types
Data typesData types
Data types
 

Recently uploaded

Planning a health career 4th Quarter.pptx
Planning a health career 4th Quarter.pptxPlanning a health career 4th Quarter.pptx
Planning a health career 4th Quarter.pptxLigayaBacuel1
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 
Romantic Opera MUSIC FOR GRADE NINE pptx
Romantic Opera MUSIC FOR GRADE NINE pptxRomantic Opera MUSIC FOR GRADE NINE pptx
Romantic Opera MUSIC FOR GRADE NINE pptxsqpmdrvczh
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceSamikshaHamane
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 
How to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPHow to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPCeline George
 
Grade 9 Q4-MELC1-Active and Passive Voice.pptx
Grade 9 Q4-MELC1-Active and Passive Voice.pptxGrade 9 Q4-MELC1-Active and Passive Voice.pptx
Grade 9 Q4-MELC1-Active and Passive Voice.pptxChelloAnnAsuncion2
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTiammrhaywood
 
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...Nguyen Thanh Tu Collection
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPCeline George
 
Keynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designKeynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designMIPLM
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 
ENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomnelietumpap1
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17Celine George
 
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfAMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfphamnguyenenglishnb
 
ROOT CAUSE ANALYSIS PowerPoint Presentation
ROOT CAUSE ANALYSIS PowerPoint PresentationROOT CAUSE ANALYSIS PowerPoint Presentation
ROOT CAUSE ANALYSIS PowerPoint PresentationAadityaSharma884161
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 

Recently uploaded (20)

Planning a health career 4th Quarter.pptx
Planning a health career 4th Quarter.pptxPlanning a health career 4th Quarter.pptx
Planning a health career 4th Quarter.pptx
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 
Romantic Opera MUSIC FOR GRADE NINE pptx
Romantic Opera MUSIC FOR GRADE NINE pptxRomantic Opera MUSIC FOR GRADE NINE pptx
Romantic Opera MUSIC FOR GRADE NINE pptx
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in Pharmacovigilance
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 
How to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPHow to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERP
 
Grade 9 Q4-MELC1-Active and Passive Voice.pptx
Grade 9 Q4-MELC1-Active and Passive Voice.pptxGrade 9 Q4-MELC1-Active and Passive Voice.pptx
Grade 9 Q4-MELC1-Active and Passive Voice.pptx
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERP
 
Keynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designKeynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-design
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
ENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choom
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17
 
OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...
 
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfAMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
 
ROOT CAUSE ANALYSIS PowerPoint Presentation
ROOT CAUSE ANALYSIS PowerPoint PresentationROOT CAUSE ANALYSIS PowerPoint Presentation
ROOT CAUSE ANALYSIS PowerPoint Presentation
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 

C Language Interview Questions: Data Types, Pointers, Data Structures, Memory Management

  • 1. www.login360.in +91-63 85 87 28 10 enquiry@login360.in 1 Interview Questions For C Language 1. What is C programming language? Ans: C is a widely used, simple-to-learn, and flexible general-purpose programming language. This structured programming language may be used to construct a wide range of software, including more complex ones like the Python interpreter, the Git repository, the Oracle database, and others, as well as operating systems like Windows. 2. What are the basic data types in C? Ans: In C, there are four fundamental data types: double floating-point, floating-point, characters, and integers. These data types are used in C programmes to specify variables and functions. 1. Integer: Integers are used to represent whole numbers. Copies may or may not have a signature. To declare integer variables, use the "int" keyword. 2. Character: Single characters, such as letters, numerals, and symbols, are represented by characters. They are declared using the "char" keyword. 3. Floating-point: Float-point data types are used to represent actual numbers with decimal points. Either single precision or double precision is possible. Declaring floating-point variables requires the use of the "float" and "double" keywords. 4. Double floating-point: Double floating-point data types more accurately reflect actual numbers when compared to floating-point data types. For example, int x = 10; char c = 'A'; float f = 3.14; double d = 3.14159; 3.What is a constant and how is it declared in C? Ans: A constant is a value in a program that cannot be changed during its execution. In C, constants are declared using the "const" keyword. Once a constant is defined, its value cannot be changed throughout the program's execution. Constants can be used in place of literal values to make code more readable and maintainable. The syntax for declaring a constant in C is as follows: const data_type constant_name = value; 4. What are the different types of operators in C? Ans: Operators in the C programming language are symbols that denote specific actions to be taken on operands (variables, constants, or expressions). In C, there are several kinds of operators, such as:
  • 2. www.login360.in +91-63 85 87 28 10 enquiry@login360.in 2 1. Arithmetic Operators: Used for addition, subtraction, multiplication, division, and modulus operations. Examples include plus (+), minus (-), * (multiplication), / (division), and % (modulus). 2. Relational Operators: These are used to compare two values and return either true or false as a boolean value. For instance,!= (not equal), == (equality), (less than), > (greater than), = (less than or equal to), and >= (greater than or equal to) 3. Logical Operators: These are used to combine two or more relational expressions and return a boolean (true or false) value. Example:! (logical not), || (logical either), and && (logical and). 4. Bitwise Operators: These are used to perform bitwise operations at the bit level on two operands. Example: & (bitwise and), | (bitwise or), ^ (bitwise exclusive or), ~ (bitwise complement), << (left shift), >> (right shift) 5. Assignment operators : Are employed to simultaneously assign a value to a variable and carry out an action. Example: = (simple assignment), += (add and assign), -= (subtract and assign), *= (multiply and assign), /= (divide and assign), %= (modulus and assign), <<= (left shift and assign), >>= (right shift and assign), &= (bitwise and and assign), |= (bitwise or and assign), ^= (bitwise exclusive or and assign) 6. Use a Conditional operation dependent on the outcome of a boolean expression by using a conditional operator. Example: ?: (conditional operator) 7. Sizeof Operator: Used to calculate a data type or variable's size in bytes. 1. Example: sizeof(int), sizeof(char), sizeof(float) 8. Address and Pointer Operators: Used to manipulate memory addresses and pointers. 1. Example: & (address of), * (pointer to) These operators can be used in numerous ways to produce complicated expressions that carry out various actions in a C program. 5. What is a conditional statement in C? Ans: In C programming, conditional statements are employed to base decisions on the circumstances. In C, conditional statements are processed sequentially if there is no condition around them. If a condition is added to a block of statements, the execution flow may change depending on how the condition is evaluated. In "C", this procedure is known as decision-making. The following two structures in C can be used to create conditional statements:  If statement  If-else statement
  • 3. www.login360.in +91-63 85 87 28 10 enquiry@login360.in 3 6. What is a loop in C? Ans: A loop is a programming technique that enables the repeated execution of a block of code depending on certain circumstances. C supports "while" loops, "do-while" loops, and "for" loops as its three different forms of loops.  The "while" loop executes the block of code as long as a certain condition is true.  The "do-while" loop executes the block of code at least once, and then repeatedly as long as a certain condition is true.  The "for" loop executes the block of code a certain number of times, based on an initialization, condition, and update statement. Loops are useful in situations where the same code needs to be executed multiple times with different values. They help to reduce code duplication and improve code efficiency. 7. What is a header file in C and how is it used? Ans : The term "header file" refers to a file with the extension ".h" that includes shared C function declarations and macro definitions. There are two different kinds of header files: those created by the programmer and those provided by the compiler. For example, if you want to use the "printf" function in your C program, you would include the "stdio.h" header file which contains the prototype for the "printf" function: #include <stdio.h> int main() { printf("Hello, world!n"); return 0; } The "#include" directive instructs the C preprocessor to copy the contents of the "stdio.h" file into your source file before compilation. This allows you to use the functions and declarations in the header file without having to rewrite them in your source code. 8. What is a structure in C and how is it declared? Ans: A user-defined data type called a structure enables you to unify variables of various data kinds under a single name. In C, a structure is declared by using the "struct" keyword, the structure's name, and a set of braces that enclose the variables that make up the structure. A structure is declared in C using the following syntax: struct structure_name { data_type1 variable_name1; data_type2 variable_name2; ... data_typen variable_namen; }; Here, "structure_name" is the name of the structure, and "variable_name1" through "variable_namen" are the names of the variables that make up the structure. The variables can be of any data type, including other structures.
  • 4. www.login360.in +91-63 85 87 28 10 enquiry@login360.in 4 Once a structure is declared, you can create variables of that structure type and access the variables inside the structure using the dot (".") operator. 9. What are the different data types in C language? Ans: The different data types in C language are int, char, float, double, and void. 1. int - used to represent integer values 2. float - used to represent floating-point values with single precision 3. double - used to represent floating-point values with double precision 4. char - used to represent a single character or an integer value that corresponds to a character in the ASCII table. In addition to these basic data types, C also provides the following derived data types: 1. Arrays - used to store a collection of values of the same data type 2. Pointers - used to store memory addresses of variables 3. Structures - used to group together variables of different data types under a single name 4. Unions - used to allocate memory for multiple variables of different data types but only one variable can be accessed at a time 5. Enumerations - used to define a set of named constants. 10. What is a function in C language? Ans: A function in C language is a block of code that performs a specific task and can be called from anywhere in the program (e.g. int add(int x, int y) { return x + y; }). 11. What is a string in C and how is it declared? Ans: In C, a string is a sequence of characters stored in consecutive memory locations. To declare a string, you can use the character array data type, where each element of the array represents a character in the string, and the last element is the null terminator '0'. Here's an example of declaring a string in C: Example: char myString[] = "Hello, World!"; Here, `myString` is an array of characters that contains the string "Hello, World!". Note that the null terminator is automatically added to the end of the string. 12. Why is C called a mid-level programming language? Ans: C is called a mid-level programming language because it has features of both low-level and high-level programming languages. It provides low-level access to memory through
  • 5. www.login360.in +91-63 85 87 28 10 enquiry@login360.in 5 pointers and high-level abstractions such as functions, control structures, and data types. This makes it suitable for writing both system-level and application-level software. 13. What is the use of printf() and scanf() functions? Also explain format specifiers? Ans: The `printf()` function is used for displaying output to the console or other output devices. The `scanf()` function is used for reading input from the console or other input devices. Format specifiers are special codes used in formatted input and output functions to indicate the type of data being read or written. They are preceded by a `%` symbol in the format string. To specify the type of data being read or written, format specifiers are codes used in C's formatted input and output functions. They instruct the function on the expected kind of data and the formatting to be used when it is displayed or written. The most common format specifiers are:  %d: for integer values  %f: for floating-point values  %c: for characters  %s: for strings  %p: for pointer values  %o: for octal values  %x or %X: for hexadecimal values 14. What is a Preprocessor?  The preprocessor is a component of the C compiler that processes the source code before it is compiled.  It performs a set of operations on the code, such as macro expansion, file inclusion, and conditional compilation.  The preprocessor is invoked by special commands called preprocessor directives, which begin with a hash symbol (#).  The most commonly used preprocessor directives are #define, #include, and #ifdef.  The #define directive is used to create a macro, which is a symbolic name that is replaced with a corresponding value in the code.  The #include directive is used to include a header file in the code.  The #ifdef directive is used to check if a certain macro is defined, and conditionally include or exclude code based on its value. 15. What is a pointer in C? Ans: A pointer in C is a variable that stores the memory address of another variable. It is declared using the `*` symbol, and can be used to indirectly access and manipulate the values stored in memory locations. Here's a example of using a pointer to assign a value to a variable in C: ``` #include <stdio.h> int main() { int x = 5;
  • 6. www.login360.in +91-63 85 87 28 10 enquiry@login360.in 6 int *ptr; ptr = &x; *ptr = 10; printf("The value of x is %dn", x); return 0; } ``` In this example, we declare an integer variable `x` and set its initial value to `5`. We also declare an integer pointer `ptr`, and assign it the memory address of `x` using the `&` operator. We then use the `*` operator to dereference `ptr` and assign the value `10` to the memory location pointed to by `ptr`. This effectively changes the value of `x` to `10`. Finally, we use `printf()` to print the updated value of `x`. 16. What is typecasting in C? Ans: The process of changing a variable's datatype is known as typecasting. We must explicitly transform the data type into another data type if we wish to save a huge type value as an int type. Syntax: (data_type)expression; For Example: int x; for(x=97; x<=122; x++) { printf("%c", (char)x); /*Explicit casting from int to char*/ } 17. What is recursion in C? Ans: Recursion occurs when a C function calls a duplicate of itself. To put it another way, this method is known as recursion when a function calls itself. This function is also referred to as a recursive function. Syntax of Recursive Function: void do_recursion() { ... .. ... do_recursion(); ... .. ...] } int main() { ... .. ... do_recursion(); ... .. ... } 18. Why doesn’t C support function overloading?
  • 7. www.login360.in +91-63 85 87 28 10 enquiry@login360.in 7 Function overloading is not supported by C since it is unable to differentiate between functions based on their signatures (parameter types and number of arguments). If you attempt to declare more than one function with the same name in C, a compilation error will take place. Each function has to be given a unique name. For example, the following code is not allowed in C: ``` int add(int a, int b) { return a + b; } float add(float a, float b) { return a + b; } ``` Because C++ supports function signature differentiation, which enables functions with the same name to be distinguished based on their parameter types and/or a number of parameters, function overloading is possible. 19. What are Enumerations? Ans: Enumerations in C are user-defined data types used to assign names to integer constants, making it easier to read and maintain code. An enumeration consists of a set of named integer constants, known as enumerators or members, which are typically used to represent a finite set of values for a given variable. For Example: #include <stdio.h> enum Days {Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday}; int main() { enum Days today = Wednesday; printf("Today is %dn", today); // Output: Today is 2 return 0; } In this example, we declare an enumeration called `Days` that has seven possible values - `Monday`, `Tuesday`, `Wednesday`, `Thursday`, `Friday`, `Saturday`, and `Sunday`. We then declare a variable called `today` of type `Days` and assign it the value `Wednesday`. We then print out the value of `today`, which is `2` because `Wednesday` is the third value in the enumeration (counting from `0`). 20. What is the difference between global int and static int declaration? Ans: The main difference between a global `int` and a `static int` declared inside a function is their scope and lifetime.
  • 8. www.login360.in +91-63 85 87 28 10 enquiry@login360.in 8 A global `int` variable is declared outside of any function and has a global scope, which means it can be accessed by any function in the program. It also has a lifetime that lasts for the entire duration of the program. On the other hand, a `static int` variable declared inside a function has a local scope, which means it can only be accessed by that function. However, it has a lifetime that lasts for the entire duration of the program, just like a global variable. Additionally, a `static int` variable retains its value between function calls, whereas a regular local variable would be re- initialized each time the function is called. In summary, a global `int` variable can be accessed by any function in the program, whereas a `static int` variable declared inside a function is limited to that function's scope, but retains its value between function calls. 21. What is the difference between a structure and a union in C? In C, a structure is a user-defined composite data type that groups together related data of different data types under a single name. A union, on the other hand, is also a user-defined composite data type that allows storing different data types in the same memory location at different times. The main difference between a structure and a union is in the way they store and access data. In a structure, each member variable has its own memory location, while in a union, all members share the same memory location. This means that modifying one member of a union will change the value of all other members as well. Additionally, the size of a union is determined by the size of its largest member, while the size of a structure is the sum of the sizes of all its members. For examples: 1. Example of a structure in C: ``` struct person { char name[50]; int age; float salary; }; int main() { struct person p1; // Declaring a variable of type struct person // Assigning values to the members of the structure strcpy(p1.name, "John"); p1.age = 25; p1.salary = 5000.0; // Accessing the members of the structure printf("Name: %sn", p1.name); printf("Age: %dn", p1.age); printf("Salary: %.2fn", p1.salary);
  • 9. www.login360.in +91-63 85 87 28 10 enquiry@login360.in 9 return 0; } ``` 2. Example of a union in C: ``` union data { int i; float f; char c; }; int main() { union data d; // Declaring a variable of type union data d.i = 10; // Assigning a value to the integer member printf("i = %dn", d.i); d.f = 3.14; // Assigning a value to the float member printf("f = %.2fn", d.f); d.c = 'a'; // Assigning a value to the character member printf("c = %cn", d.c); return 0; }
  • 10. www.login360.in +91-63 85 87 28 10 enquiry@login360.in 10 Enquiry Now www.login360.in +91-63 85 87 28 10 enquiry@login360.in