SlideShare a Scribd company logo
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:
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:
1. If statement
2. If-else statement
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.
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 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?
Ans: 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;
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?
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.
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);
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;
}
Enquiry now
https://login360.in/
+91-63 85 87 28 10
enquiry@login360.in

More Related Content

Similar to Interview Questions For C Language (20)

PPTX
Interview Questions For C Language .pptx
Rowank2
 
PDF
C Language Interview Questions: Data Types, Pointers, Data Structures, Memory...
Rowank2
 
DOCX
Computer programming questions
estoredesignerclothi
 
PDF
C Interview Questions PDF By Scholarhat.pdf
Scholarhat
 
PPTX
C programming language tutorial
Dr. SURBHI SAROHA
 
PDF
Fundamentals of c language
AkshhayPatel
 
PPT
Introduction to c
sunila tharagaturi
 
PDF
Unit 1
Sowri Rajan
 
PDF
cprogramming questions for practice end term
Sheelendra3
 
PDF
Top interview questions in c
Avinash Seth
 
PPTX
Top 40 C Programming Interview Questions
Simplilearn
 
PDF
Reduce course notes class xii
Syed Zaid Irshad
 
PDF
C interview questions
Soba Arjun
 
PPTX
the refernce of programming C notes ppt.pptx
AnkitaVerma776806
 
PPTX
C programming tutorial for Beginner
sophoeutsen2
 
PPTX
What is c
Nitesh Saitwal
 
PPTX
PPS_unit_2_gtu_sem_2_year_2023_GTUU.pptx
ZwecklosSe
 
DOCX
Complete c programming presentation
nadim akber
 
PPTX
C_Programming_Language_tutorial__Autosaved_.pptx
Likhil181
 
PPTX
C presentation! BATRA COMPUTER CENTRE
jatin batra
 
Interview Questions For C Language .pptx
Rowank2
 
C Language Interview Questions: Data Types, Pointers, Data Structures, Memory...
Rowank2
 
Computer programming questions
estoredesignerclothi
 
C Interview Questions PDF By Scholarhat.pdf
Scholarhat
 
C programming language tutorial
Dr. SURBHI SAROHA
 
Fundamentals of c language
AkshhayPatel
 
Introduction to c
sunila tharagaturi
 
Unit 1
Sowri Rajan
 
cprogramming questions for practice end term
Sheelendra3
 
Top interview questions in c
Avinash Seth
 
Top 40 C Programming Interview Questions
Simplilearn
 
Reduce course notes class xii
Syed Zaid Irshad
 
C interview questions
Soba Arjun
 
the refernce of programming C notes ppt.pptx
AnkitaVerma776806
 
C programming tutorial for Beginner
sophoeutsen2
 
What is c
Nitesh Saitwal
 
PPS_unit_2_gtu_sem_2_year_2023_GTUU.pptx
ZwecklosSe
 
Complete c programming presentation
nadim akber
 
C_Programming_Language_tutorial__Autosaved_.pptx
Likhil181
 
C presentation! BATRA COMPUTER CENTRE
jatin batra
 

Recently uploaded (20)

PDF
Generative AI: it's STILL not a robot (CIJ Summer 2025)
Paul Bradshaw
 
PPTX
How to Set Maximum Difference Odoo 18 POS
Celine George
 
PPTX
ASRB NET 2023 PREVIOUS YEAR QUESTION PAPER GENETICS AND PLANT BREEDING BY SAT...
Krashi Coaching
 
PPTX
SPINA BIFIDA: NURSING MANAGEMENT .pptx
PRADEEP ABOTHU
 
PDF
CONCURSO DE POESIA “POETUFAS – PASSOS SUAVES PELO VERSO.pdf
Colégio Santa Teresinha
 
PPTX
How to Convert an Opportunity into a Quotation in Odoo 18 CRM
Celine George
 
PPTX
I AM MALALA The Girl Who Stood Up for Education and was Shot by the Taliban...
Beena E S
 
PPTX
PATIENT ASSIGNMENTS AND NURSING CARE RESPONSIBILITIES.pptx
PRADEEP ABOTHU
 
PPT
Talk on Critical Theory, Part One, Philosophy of Social Sciences
Soraj Hongladarom
 
PDF
LAW OF CONTRACT ( 5 YEAR LLB & UNITARY LLB)- MODULE-3 - LEARN THROUGH PICTURE
APARNA T SHAIL KUMAR
 
PPTX
2025 Winter SWAYAM NPTEL & A Student.pptx
Utsav Yagnik
 
PDF
0725.WHITEPAPER-UNIQUEWAYSOFPROTOTYPINGANDUXNOW.pdf
Thomas GIRARD, MA, CDP
 
PDF
Reconstruct, Restore, Reimagine: New Perspectives on Stoke Newington’s Histor...
History of Stoke Newington
 
PDF
Dimensions of Societal Planning in Commonism
StefanMz
 
PDF
DIGESTION OF CARBOHYDRATES,PROTEINS,LIPIDS
raviralanaresh2
 
PPTX
STAFF DEVELOPMENT AND WELFARE: MANAGEMENT
PRADEEP ABOTHU
 
PDF
ARAL_Orientation_Day-2-Sessions_ARAL-Readung ARAL-Mathematics ARAL-Sciencev2.pdf
JoelVilloso1
 
PPTX
Growth and development and milestones, factors
BHUVANESHWARI BADIGER
 
PDF
QNL June Edition hosted by Pragya the official Quiz Club of the University of...
Pragya - UEM Kolkata Quiz Club
 
PDF
community health nursing question paper 2.pdf
Prince kumar
 
Generative AI: it's STILL not a robot (CIJ Summer 2025)
Paul Bradshaw
 
How to Set Maximum Difference Odoo 18 POS
Celine George
 
ASRB NET 2023 PREVIOUS YEAR QUESTION PAPER GENETICS AND PLANT BREEDING BY SAT...
Krashi Coaching
 
SPINA BIFIDA: NURSING MANAGEMENT .pptx
PRADEEP ABOTHU
 
CONCURSO DE POESIA “POETUFAS – PASSOS SUAVES PELO VERSO.pdf
Colégio Santa Teresinha
 
How to Convert an Opportunity into a Quotation in Odoo 18 CRM
Celine George
 
I AM MALALA The Girl Who Stood Up for Education and was Shot by the Taliban...
Beena E S
 
PATIENT ASSIGNMENTS AND NURSING CARE RESPONSIBILITIES.pptx
PRADEEP ABOTHU
 
Talk on Critical Theory, Part One, Philosophy of Social Sciences
Soraj Hongladarom
 
LAW OF CONTRACT ( 5 YEAR LLB & UNITARY LLB)- MODULE-3 - LEARN THROUGH PICTURE
APARNA T SHAIL KUMAR
 
2025 Winter SWAYAM NPTEL & A Student.pptx
Utsav Yagnik
 
0725.WHITEPAPER-UNIQUEWAYSOFPROTOTYPINGANDUXNOW.pdf
Thomas GIRARD, MA, CDP
 
Reconstruct, Restore, Reimagine: New Perspectives on Stoke Newington’s Histor...
History of Stoke Newington
 
Dimensions of Societal Planning in Commonism
StefanMz
 
DIGESTION OF CARBOHYDRATES,PROTEINS,LIPIDS
raviralanaresh2
 
STAFF DEVELOPMENT AND WELFARE: MANAGEMENT
PRADEEP ABOTHU
 
ARAL_Orientation_Day-2-Sessions_ARAL-Readung ARAL-Mathematics ARAL-Sciencev2.pdf
JoelVilloso1
 
Growth and development and milestones, factors
BHUVANESHWARI BADIGER
 
QNL June Edition hosted by Pragya the official Quiz Club of the University of...
Pragya - UEM Kolkata Quiz Club
 
community health nursing question paper 2.pdf
Prince kumar
 
Ad

Interview Questions For C Language

  • 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.
  • 2. 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: 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.
  • 3. 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: 1. If statement 2. If-else statement 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; }
  • 4. 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. 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.
  • 5. 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 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
  • 6. ● %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? Ans: 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; 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
  • 7. 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? 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
  • 8. 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
  • 9. 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. 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];
  • 10. 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); 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; }