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

What's hot

Arrays
ArraysArrays
SEARCHING AND SORTING ALGORITHMS
SEARCHING AND SORTING ALGORITHMSSEARCHING AND SORTING ALGORITHMS
SEARCHING AND SORTING ALGORITHMS
Gokul Hari
 
Java: Primitive Data Types
Java: Primitive Data TypesJava: Primitive Data Types
Java: Primitive Data Types
Tareq Hasan
 
Graphs in datastructures
Graphs in datastructuresGraphs in datastructures
Graphs in datastructures
LikhithaGunturi
 
Data structures & algorithms lecture 3
Data structures & algorithms lecture 3Data structures & algorithms lecture 3
Data structures & algorithms lecture 3
Poojith Chowdhary
 
Counting sort
Counting sortCounting sort
Counting sort
zahraa F.Muhsen
 
Vector class in C++
Vector class in C++Vector class in C++
Vector class in C++
Jawad Khan
 
HTML Marquee
HTML MarqueeHTML Marquee
HTML Marquee
Hameda Hurmat
 
Collision in Hashing.pptx
Collision in Hashing.pptxCollision in Hashing.pptx
Collision in Hashing.pptx
NBACriteria2SICET
 
Quick sort
Quick sortQuick sort
Quick sort
Dhruv Sabalpara
 
ADA_2_Analysis of Algorithms
ADA_2_Analysis of AlgorithmsADA_2_Analysis of Algorithms
ADA_2_Analysis of Algorithms
Khushali Kathiriya
 
Doubly Linked List
Doubly Linked ListDoubly Linked List
Doubly Linked List
Ninad Mankar
 
Trees (data structure)
Trees (data structure)Trees (data structure)
Trees (data structure)
Trupti Agrawal
 
Java Streams
Java StreamsJava Streams
Java Streams
M Vishnuvardhan Reddy
 
Dynamic Memory Allocation(DMA)
Dynamic Memory Allocation(DMA)Dynamic Memory Allocation(DMA)
Dynamic Memory Allocation(DMA)
Kamal Acharya
 
Dijkstra algorithm
Dijkstra algorithmDijkstra algorithm
Dijkstra algorithm
A. S. M. Shafi
 

What's hot (20)

Arrays
ArraysArrays
Arrays
 
SEARCHING AND SORTING ALGORITHMS
SEARCHING AND SORTING ALGORITHMSSEARCHING AND SORTING ALGORITHMS
SEARCHING AND SORTING ALGORITHMS
 
Java: Primitive Data Types
Java: Primitive Data TypesJava: Primitive Data Types
Java: Primitive Data Types
 
Graphs in datastructures
Graphs in datastructuresGraphs in datastructures
Graphs in datastructures
 
Data structures & algorithms lecture 3
Data structures & algorithms lecture 3Data structures & algorithms lecture 3
Data structures & algorithms lecture 3
 
Counting sort
Counting sortCounting sort
Counting sort
 
Vector class in C++
Vector class in C++Vector class in C++
Vector class in C++
 
HTML Marquee
HTML MarqueeHTML Marquee
HTML Marquee
 
Collision in Hashing.pptx
Collision in Hashing.pptxCollision in Hashing.pptx
Collision in Hashing.pptx
 
Quick sort
Quick sortQuick sort
Quick sort
 
ADA_2_Analysis of Algorithms
ADA_2_Analysis of AlgorithmsADA_2_Analysis of Algorithms
ADA_2_Analysis of Algorithms
 
single linked list
single linked listsingle linked list
single linked list
 
Strings
StringsStrings
Strings
 
Sorting
SortingSorting
Sorting
 
Doubly Linked List
Doubly Linked ListDoubly Linked List
Doubly Linked List
 
Trees (data structure)
Trees (data structure)Trees (data structure)
Trees (data structure)
 
Java Streams
Java StreamsJava Streams
Java Streams
 
Dynamic Memory Allocation(DMA)
Dynamic Memory Allocation(DMA)Dynamic Memory Allocation(DMA)
Dynamic Memory Allocation(DMA)
 
Dijkstra algorithm
Dijkstra algorithmDijkstra algorithm
Dijkstra algorithm
 
12 SQL
12 SQL12 SQL
12 SQL
 

Similar to Interview Questions For C Language

C Language Interview Questions: Data Types, Pointers, Data Structures, Memory...
C Language Interview Questions: Data Types, Pointers, Data Structures, Memory...C Language Interview Questions: Data Types, Pointers, Data Structures, Memory...
C Language Interview Questions: Data Types, Pointers, Data Structures, Memory...
Rowank2
 
C programming Training in Ambala ! Batra Computer Centre
C programming Training in Ambala ! Batra Computer CentreC programming Training in Ambala ! Batra Computer Centre
C programming Training in Ambala ! Batra Computer Centre
jatin batra
 
C programming notes
C programming notesC programming notes
C programming notes
Prof. Dr. K. Adisesha
 
C programming notes.pdf
C programming notes.pdfC programming notes.pdf
C programming notes.pdf
AdiseshaK
 
Basic Information About C language PDF
Basic Information About C language PDFBasic Information About C language PDF
Basic Information About C language PDF
Suraj Das
 
Aniket tore
Aniket toreAniket tore
Aniket tore
anikettore1
 
C Programming Unit-1
C Programming Unit-1C Programming Unit-1
C Programming Unit-1
Vikram Nandini
 
C language ppt
C language pptC language ppt
C language ppt
Ğäùråv Júñêjå
 
C material
C materialC material
C material
tarique472
 
venkatesh.pptx
venkatesh.pptxvenkatesh.pptx
venkatesh.pptx
KishoreRedla
 
C language
C languageC language
C language
SMS2007
 
Fundamentals of c language
Fundamentals of c languageFundamentals of c language
Fundamentals of c language
AkshhayPatel
 
unit2.pptx
unit2.pptxunit2.pptx
unit2.pptx
sscprep9
 
history of c.ppt
history of c.ppthistory of c.ppt
history of c.ppt
arpanabharani
 
Introduction%20C.pptx
Introduction%20C.pptxIntroduction%20C.pptx
Introduction%20C.pptx
20EUEE018DEEPAKM
 
C_Programming_Language_tutorial__Autosaved_.pptx
C_Programming_Language_tutorial__Autosaved_.pptxC_Programming_Language_tutorial__Autosaved_.pptx
C_Programming_Language_tutorial__Autosaved_.pptx
Likhil181
 
C intro
C introC intro
C intro
SHIKHA GAUTAM
 

Similar to Interview Questions For C Language (20)

C Language Interview Questions: Data Types, Pointers, Data Structures, Memory...
C Language Interview Questions: Data Types, Pointers, Data Structures, Memory...C Language Interview Questions: Data Types, Pointers, Data Structures, Memory...
C Language Interview Questions: Data Types, Pointers, Data Structures, Memory...
 
C programming Training in Ambala ! Batra Computer Centre
C programming Training in Ambala ! Batra Computer CentreC programming Training in Ambala ! Batra Computer Centre
C programming Training in Ambala ! Batra Computer Centre
 
C programming notes
C programming notesC programming notes
C programming notes
 
C programming notes.pdf
C programming notes.pdfC programming notes.pdf
C programming notes.pdf
 
Basic Information About C language PDF
Basic Information About C language PDFBasic Information About C language PDF
Basic Information About C language PDF
 
Aniket tore
Aniket toreAniket tore
Aniket tore
 
C Programming Unit-1
C Programming Unit-1C Programming Unit-1
C Programming Unit-1
 
C language ppt
C language pptC language ppt
C language ppt
 
C material
C materialC material
C material
 
venkatesh.pptx
venkatesh.pptxvenkatesh.pptx
venkatesh.pptx
 
C language
C languageC language
C language
 
C notes
C notesC notes
C notes
 
Fundamentals of c language
Fundamentals of c languageFundamentals of c language
Fundamentals of c language
 
unit2.pptx
unit2.pptxunit2.pptx
unit2.pptx
 
history of c.ppt
history of c.ppthistory of c.ppt
history of c.ppt
 
Introduction%20C.pptx
Introduction%20C.pptxIntroduction%20C.pptx
Introduction%20C.pptx
 
Pc module1
Pc module1Pc module1
Pc module1
 
C_Programming_Language_tutorial__Autosaved_.pptx
C_Programming_Language_tutorial__Autosaved_.pptxC_Programming_Language_tutorial__Autosaved_.pptx
C_Programming_Language_tutorial__Autosaved_.pptx
 
C intro
C introC intro
C intro
 
C LANGUAGE NOTES
C LANGUAGE NOTESC LANGUAGE NOTES
C LANGUAGE NOTES
 

Recently uploaded

Acetabularia Information For Class 9 .docx
Acetabularia Information For Class 9  .docxAcetabularia Information For Class 9  .docx
Acetabularia Information For Class 9 .docx
vaibhavrinwa19
 
Digital Artifact 2 - Investigating Pavilion Designs
Digital Artifact 2 - Investigating Pavilion DesignsDigital Artifact 2 - Investigating Pavilion Designs
Digital Artifact 2 - Investigating Pavilion Designs
chanes7
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
Jisc
 
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
Nguyen Thanh Tu Collection
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
Sandy Millin
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
Jisc
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
heathfieldcps1
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
Levi Shapiro
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
Delapenabediema
 
Marketing internship report file for MBA
Marketing internship report file for MBAMarketing internship report file for MBA
Marketing internship report file for MBA
gb193092
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
Tamralipta Mahavidyalaya
 
Francesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptxFrancesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptx
EduSkills OECD
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Thiyagu K
 
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th SemesterGuidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Atul Kumar Singh
 
A Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in EducationA Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in Education
Peter Windle
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
EugeneSaldivar
 
Best Digital Marketing Institute In NOIDA
Best Digital Marketing Institute In NOIDABest Digital Marketing Institute In NOIDA
Best Digital Marketing Institute In NOIDA
deeptiverma2406
 
Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.
Ashokrao Mane college of Pharmacy Peth-Vadgaon
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
Special education needs
 
Embracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic ImperativeEmbracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic Imperative
Peter Windle
 

Recently uploaded (20)

Acetabularia Information For Class 9 .docx
Acetabularia Information For Class 9  .docxAcetabularia Information For Class 9  .docx
Acetabularia Information For Class 9 .docx
 
Digital Artifact 2 - Investigating Pavilion Designs
Digital Artifact 2 - Investigating Pavilion DesignsDigital Artifact 2 - Investigating Pavilion Designs
Digital Artifact 2 - Investigating Pavilion Designs
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
 
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
 
Marketing internship report file for MBA
Marketing internship report file for MBAMarketing internship report file for MBA
Marketing internship report file for MBA
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
 
Francesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptxFrancesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptx
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
 
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th SemesterGuidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th Semester
 
A Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in EducationA Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in Education
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
 
Best Digital Marketing Institute In NOIDA
Best Digital Marketing Institute In NOIDABest Digital Marketing Institute In NOIDA
Best Digital Marketing Institute In NOIDA
 
Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
 
Embracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic ImperativeEmbracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic Imperative
 

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; }
  • 11. Enquiry now https://login360.in/ +91-63 85 87 28 10 enquiry@login360.in