0% found this document useful (0 votes)
21 views

C lang Interview Questions (Ed Spread)

Uploaded by

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

C lang Interview Questions (Ed Spread)

Uploaded by

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

ED SPREAD

F A L L I N T H E L O O P O F T E C H

C PROGRAMMING
INTERVIEW
QUESTIONS
ED SPREAD
F A L L I N T H E L O O P O F T E C H

What is spaghetti programming?

Spaghetti programming refers to codes that tend to get tangled and


overlapped throughout the program.
This unstructured approach to coding is usually attributed to lack of
experience on the part of the programmer.
Spaghetti programing makes a program complex and analyzing the
codes difficult, and so must be avoided as much as possible.

Compare and contrast compilers from interpreters.

Compilers and interpreters often deal with how program codes are
executed.
Interpreters execute program codes one line at a time, while compilers
take the program as a whole and convert it into object code, before
executing it.
The key difference here is that in the case of interpreters, a program
may encounter syntax errors in the middle of execution, and will stop
from there.
On the other hand, compilers check the syntax of the entire program
and will only proceed to execution when no syntax errors are found.

What is the dynamic memory allocation?


Allocating the memory at run time is called dynamic memory allocation.

+91-7842584260 www.edspread.in
ED SPREAD
F A L L I N T H E L O O P O F T E C H

Can I use “int” data type to store the value 32768?


Why?

No. “int” data type is capable of storing values from -32768 to 32767.
To store 32768, you can use “long int” instead.
You can also use “unsigned int”, assuming you don’t intend to store
negative values.

Write a loop statement that will show the following


output:

1
12
123
1234
12345

for (a=1; a<=5; i++) {


for (b=1; b<=a; b++)
printf("%d",b);
printf("\n");
}

+91-7842584260 www.edspread.in
ED SPREAD
F A L L I N T H E L O O P O F T E C H

What is debugging?
Debugging is the process of identifying errors within a program.
During program compilation, errors that are found will stop the
program from executing completely.
At this state, the programmer would look into the possible portions
where the error occurred.
Debugging ensures the removal of errors, and plays an important role in
ensuring that the expected program output is met.

Why C language being considered a middle level


language?
This is because C language is rich in features that make it behave like a
high level language while at the same time can interact with hardware
using low level methods.
The use of a well structured approach to programming, coupled with
English like words used in functions, makes it act as a high level
language.
On the other hand, C can directly access memory structures similar to
assembly language routines.

What are dangling pointers?


The dangling pointer points to a memory that has already been freed.

+91-7842584260 www.edspread.in
ED SPREAD
F A L L I N T H E L O O P O F T E C H

What is data type in C?


Data types in C language are defined as the data storage format that a
variable can store a data to perform a specific operation.
Data types are used to define a variable before to use in a program.
Size of variable, constant and array are determined by data types.

What is the difference between declaration and


definition of a variable?
Declaration only identifies the data type of a variable whereas
definition causes the space to be reserved for the variable.
Thus, declaration in a place where the nature of the variable is stated
but no storage is allocated whereas definition is the place where the
variable is created or assigned storage.

Specify different types of decision control statements?


All statements written in a program are executed from top to bottom one
by one.
Control statements are used to execute/transfer the control from one
part of the program to another depending on the condition.
If-else statement.
normal if-else statement.
Else-if statement
nested if-else statement.
Switch statement.

+91-7842584260 www.edspread.in
ED SPREAD
F A L L I N T H E L O O P O F T E C H

What is typedef?
typedef is a C keyword, used to define alias/synonyms for an existing
type in C language.
In most cases, we use typedef's to simplify the existing type declaration
syntax.
Or to provide specific descriptive names to a type.

Check whether the number is EVEN or ODD, without


using any arithmetic or relational operators

#include<stdio.h>
int main()
{
int x;
printf("Enter a number: ");
scanf("%d", &x);
(x&1)?printf("Odd"):printf("Even");
return 0;
}

What is recursion in C?
When a function calls itself, and this process is known as recursion.
The function that calls itself is known as a recursive function.

+91-7842584260 www.edspread.in
ED SPREAD
F A L L I N T H E L O O P O F T E C H

Add Two Numbers Without Using the Addition


Operator
#include<stdio.h>
#include<stdlib.h>
int main()
{
int x, y;
printf("Enter two number: ");
scanf("%d %d",&x,&y);

// method 1
printf("%d\n", x-(-y));

// method 2
printf("%d\n", -(-x-y));

// method 3
printf("%d\n", abs(-x-y));

// method 4
printf("%d", x-(~y)-1);

return 0;
}

+91-7842584260 www.edspread.in
ED SPREAD
F A L L I N T H E L O O P O F T E C H

What is the difference between ‘g’ and “g” in C?


In C double-quotes variables are identified as a string whereas single-
quoted variables are identified as the character.
Another major difference being the string (double-quoted) variables end
with a null terminator that makes it a 2 character array.

Name some different storage class specifiers in C?


Storage classes represent the storage of any variable. There are four
storage classes in C:
Auto
Register
Extern
Static

What do you mean by the scope and lifetime of a


variable in C?
The scope and lifetime of any variable are defined as the section of the
code in which the variable is executable or visible.
Variables that are described in the block are only accessible in the block.
The lifetime of the variable defines the existence of the variable before it
is destroyed.

+91-7842584260 www.edspread.in
ED SPREAD
F A L L I N T H E L O O P O F T E C H

What is the output of the following C code?


#include <stdlib.h>
#include <stdio.h>
enum {false, true};
int main()
{
int i = 1;
do
{
printf(“%d\n”, i);
i++;
if (i < 15)
continue;
} while (false);
getchar();
return 0;
}

Output=1
The do-while loop executes at every iteration.
After the continue statement, it will come to the while (false)
statement, and the condition shows false, and ‘i’ is printed only once.

+91-7842584260 www.edspread.in
ED SPREAD
F A L L I N T H E L O O P O F T E C H

How to write a program in C for swapping two


numbers without the use of the third variable
#include <stdio.h>
int main()
{
int x, y;
printf(“Input two integers (x & y) to swap\n”);
scanf(“%d%d”, &x, &y);
x = x + y;
y = x – y;
x = x – y;
printf(“x = %d\ny = %d\n”,x,y);
return 0;
}

Explain the difference between = and == symbols in C


programming?

The assignment operator (=): It is a binary operator used to


operate two operands. It is used to assign the value to the
variable.
Equal to operator (==): It is also a binary operator used to
compare the left-hand side and right-hand side value, if it is the
same, it returns 1 else 0.

+91-7842584260 www.edspread.in
ED SPREAD
F A L L I N T H E L O O P O F T E C H

What is the use of the function in C?


Uses of C function are:
C functions are used to avoid the rewriting the same code again and
again in our program.
C functions can be called any number of times from any place of our
program.
When a program is divided into functions, then any part of our program
can easily be tracked.
C functions provide the reusability concept, i.e., it breaks the big task
into smaller tasks so that it makes the C program more understandable.

What is an array in C?
An Array is a group of similar types of elements.
It has a contiguous memory location.
It makes the code optimized, easy to traverse and easy to sort.
The size and type of arrays cannot be changed after its declaration.

+91-7842584260 www.edspread.in
ED SPREAD
F A L L I N T H E L O O P O F T E C H

What is a pointer in C?
A pointer is a variable that refers to the address of a value.
It makes the code optimized and makes the performance fast.
Whenever a variable is declared inside a program, then the system
allocates some memory to a variable.
The memory contains some address number.
The variables that hold this address number is known as the pointer
variable.

What is the structure?


The structure is a user-defined data type that allows storing multiple
types of data in a single unit. It occupies the sum of the memory of all
members.
The structure members can be accessed only through structure
variables.
Structure variables accessing the same structure but the memory
allocated for each variable will be different.

What is a NULL Pointer? Whether it is same as an


uninitialized pointer?
Null pointer is a pointer which points to nothing but uninitialized pointer
may point to
anywhere

+91-7842584260 www.edspread.in
ED SPREAD
F A L L I N T H E L O O P O F T E C H

What are C identifiers?


These are names given to various programming element such as
variables, function,
arrays.It is a combination of letter, digit and underscore.It should begin
with letter. Backspace is
not allowed.

What is a file?
A file is a region of storage in hard disks or in auxiliary storage devices. It
contains bytes of
information .It is not a data type.

What is a file pointer?


The pointer to a FILE data type is called as a stream pointer or a file
pointer. A file pointer
points to the block of information of the stream that had just been
opened.

+91-7842584260 www.edspread.in
ED SPREAD
F A L L I N T H E L O O P O F T E C H

Represent a two-dimensional array using pointer?

Address of a[I][j] Value of a[I][j]


&a[I][j]
or
a[I] + j
or
*(a+I) + j
*&a[I][j] or a[I][j]
or
*(a[I] + j )
or
*( * ( a+I) +j )

Differentiate between an internal static and external


static variable?

In C language, the external static variable has the internal linkage and
the internal static variable has no linkage.
It is the reason they have a different scope but both will alive
throughout the program.

A external static variable ===>>> internal linkage.


A internal static variable ===>>> none .

+91-7842584260 www.edspread.in
ED SPREAD
F A L L I N T H E L O O P O F T E C H

What is the output of the below C program?

#include <stdio.h>
int main()
{
int pos = 14;
float data = 1.2;
printf("%*f",pos,data);

return 0;
}
The output of the above code will be 1.200000 with 6 space.

What is the output of the below program?

#include <stdio.h>
int main()
{
int data = 16;
data = data >> 1;
printf("%d\n", data );

return 0;
}

+91-7842584260 www.edspread.in
ED SPREAD
F A L L I N T H E L O O P O F T E C H

What is a Function Pointer?


A function pointer is similar to the other pointers but the only
difference is that it points to a function instead of the variable.
In the other word, we can say, a function pointer is a type of pointer
that store the address of a function and these pointed function can be
invoked by function pointer in a program whenever required.

Differentiate between Actual Parameters and Formal


Parameters.
The Parameters which are sent from main function to the subdivided
function are called as Actual Parameters and
the parameters which are declared a the Subdivided function end are
called as Formal Parameters.

What is a C Token?
Keywords, Constants, Special Symbols, Strings, Operators, Identifiers
used in C program are referred to as C Tokens.

What is /0 character?
The Symbol mentioned is called a Null Character. It is considered as the
terminating character used in strings to notify the end of the string to
the compiler.

+91-7842584260 www.edspread.in
ED SPREAD
F A L L I N T H E L O O P O F T E C H

Explain toupper() with an example.


toupper() is a function designed to convert lowercase
words/characters into upper case.
#include&lt;stdio.h&gt;
#include&lt;ctype.h&gt;
int main()
{
char c;
c=a;
printf("%c after conversions %c", c, toupper(c));
c=B;
printf("%c after conversions %c", c, toupper(c));
}
Output
a after conversions A
B after conversions B

What is typecasting?

Typecasting is a process of converting one data type into another is


known as typecasting.
If we want to store the floating type value to an int type, then we will
convert the data type into another data type explicitly.

+91-7842584260 www.edspread.in
ED SPREAD
F A L L I N T H E L O O P O F T E C H

Mention File operations in C Language.

Basic File Handling Techniques in C, provide the basic


functionalities that user can perform against files in the system.

Function Operation
fopen() To Open a File
fclose() To Close a File
fgets() To Read a File
fprint() To Write into a File

What is Bubble Sort Algorithm?

Bubble sort is a simple sorting algorithm that repeatedly steps through


the list, compares adjacent elements and swaps them if they are in the
wrong order.
The pass through the list is repeated until the list is sorted.

Write a program to print "hello world" without using


a semicolon?

#include<stdio.h>
void main(){
if(printf("hello world")){}
}

+91-7842584260 www.edspread.in
ED SPREAD
F A L L I N T H E L O O P O F T E C H

Factorial Program in C of a given number using for


Loop
#include<stdio.h>
int main()
{
int i,num,factorial=1;
printf("Enter a whole number to find Factorial = ");
scanf("%d",&num);
for(i=1;i<=num;i++){
factorial=factorial*i;
}
printf("Factorial of %d is: %d",num,factorial);
return 0;
}

What is a nested loop?


It is also a type of loop which runs within another loop is called nested loop.
Syntax :
for(initialization; condition; increment/decrement)
{
Statements
for(initialization; condition; increment/decrement)
{
statements
}
}

+91-7842584260 www.edspread.in
ED SPREAD
F A L L I N T H E L O O P O F T E C H

Switch in C Language with example.


A switch statement allows to test a variable for equality against a list of
cases.
It is good practice to use switch statement than nested if…else .

Because switch is faster than nested if…else(not always).


#include <stdio.h>
int main () {
int division = 3;
switch(division) {
case 1 :
printf("1st Division\n" );
break;
case 2 :
printf("2nd Division\n" );
break;
case 3 :
printf("3rd Division\n" );
break;
default :
printf("runner up\n" );
}
return 0;
}

+91-7842584260 www.edspread.in
ED SPREAD
F A L L I N T H E L O O P O F T E C H

What is union in C?
The union is also user-defined data type.
Union allows to combine data items of different kinds. Union doesn’t
occupy the sum of the memory of all members.
It holds only the memory of the largest member only. In union, we can
access only one variable at a time.
It allocates one common space for all the members of a union.

How to write your own sizeof operator?


#define my_sizeof(type) (char *)(&type+1)-(char*)(&type)

What is volatile keyword?


The volatile keyword is intended to prevent the compiler from applying
any optimizations on objects that can change in ways that cannot be
determined by the compiler.
Objects declared as volatile are omitted from optimization because
their values can be changed by code outside the scope of current code at
any time.

+91-7842584260 www.edspread.in
ED SPREAD
F A L L I N T H E L O O P O F T E C H

Please explain what do you understand by while(0)


and while(1)?
while(0) means that the looping conditions will always be false, i.e., the
code inside the while loop will not be executed.
On the opposite, while(1) is an infinite loop. It runs continuously until
coming across a break statement mentioned explicitly.

Explain the purpose of the ‘delete’ operator?


Delete removes all the objects created by the new expression, i.e. frees
memory in the heap space. The array objects are deleted using the []
operator:
delete[] array;
NULL or void Pointer can be deleted as:
delete ptr;
The same is applicable for user-defined data types as well. For example,
int *var = new int;
delete var;

+91-7842584260 www.edspread.in
ED SPREAD
F A L L I N T H E L O O P O F T E C H

How is the null pointer different from a void pointer?


A pointer is initialized as NULL when its value isn’t known at the time of
declaration.
Generally, NULL pointers do not point to a valid location. Unlike NULL
pointers, void pointers are general-purpose pointers that do not have
any data type associated with them.
Void pointers can contain the address of any type of variable.
So, the data type that a void pointer points to can be anything.

Please explain a self-referential structure.


A self-referential structure contains the same structure pointer variable
as its element.
In other words, it is a data structure in which the pointer points to the
structure of the same data type.
A self-referential structure is used in Graphs, Heaps, Linked Lists,
Trees, et cetera.

What is macro?
A macro is a pre-processor directive and it replaces the value before
compiling the code.
One of the major problems with the macro is that there is no type
checking.
Generally, the macro is used to create the alias, in C language.
A macro is also used as a file guard in C and C++.

+91-7842584260 www.edspread.in

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy