PROGRAMING
PROGRAMING
BY MAXZZY
Ans: The Datatypes in C Language are broadly classified into 4 categories. They are as
follows:
Basic Datatypes
Derived Datatypes
Enumerated Datatypes
Void Datatypes
Q3. What do you mean by the Scope of the variable? What is the scope of
the variables in C?
Ans: Scope of the variable can be defined as the part of the code area where the
variables declared in the program can be accessed directly. In C, all identifiers are
lexically (or statically) scoped.
Ans: The variables and functions that are declared using the keyword Static are
considered as Static Variable and Static Functions. The variables declared using Static
keyword will have their scope restricted to the function in which they are declared.
Ans: calloc() and malloc() are memory dynamic memory allocating functions. The only
difference between them is that calloc() will load all the assigned memory locations with
value 0 but malloc() will not.
Q6. What are the valid places where the programmer can apply Break
Control Statement?
Ans: Break Control statement is valid to be used inside a loop and Switch control
statements.
Ans: To store a negative integer, we need to follow the following steps. Calculate the
two’s complement of the same positive integer.
Ans: 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.
Ans: The program will be compiled but will not be executed. To execute any C program,
main() is required.
Ans: When a data member of one structure is referred by the data member of another
function, then the structure is called a Nested Structure.
In case you are facing any challenges with these C Programming Interview Questions,
please write your problems in the comment section below.
Ans:
Ans: printf() is used to print the values on the screen. To print certain values, and on the
other hand, scanf() is used to scan the values. We need an appropriate datatype format
specifier for both printing and scanning purposes. For example,
%d: It is a datatype format specifier used to print and scan an integer value.
%s: It is a datatype format specifier used to print and scan a string.
%c: It is a datatype format specifier used to display and scan a character value.
%f: It is a datatype format specifier used to display and scan a float value.
Ans. The array is a simple data structure that stores multiple elements of the same
datatype in a reserved and sequential manner. There are three types of arrays, namely,
Q18. What is the main difference between the Compiler and the
Interpreter?
Ans: Compiler is used in C Language and it translates the complete code into the
Machine Code in one shot. On the other hand, Interpreter is used in Java Programming
Langauge and other high-end programming languages. It is designed to compile code in
line by line fashion.
Ans: No, Integer datatype will support the range between -32768 and 32767. Any value
exceeding that will not be stored. We can either use float or long int.
Want to upskill yourself to get ahead in your career? Check out this video
This Edureka video on 𝐓𝐨𝐩 𝟏𝟎 𝐓𝐞𝐜𝐡𝐧𝐨𝐥𝐨𝐠𝐢𝐞𝐬 𝐭𝐨 𝐋𝐞𝐚𝐫𝐧 𝐢𝐧 𝟐𝟎𝟐𝟐 will introduce you to all
the popular and trending technologies in the market which you should focus on in 2022.
You need to learn these trending technologies for a successful career in 2022.
Intermediate C Interview Questions
Ans: Dynamic Memory Allocation is the process of allocating memory to the program and
its variables in runtime. Dynamic Memory Allocation process involves three functions for
allocating memory and one function to free the used memory.
Syntax:
Syntax:
Syntax:
Syntax:
1 free(ptr);
Ans: Structure is defined as a user-defined data type that is designed to store multiple
data members of the different data types as a single unit. A structure will consume the
memory equal to the summation of all the data members.
1
2 struct employee
3 {
4 char name[10];
5 int age;
}e1;
6 int main()
7 {
8 printf("Enter the name");
9 scanf("%s",e1.name);
10 printf("n");
printf("Enter the age");
11 scanf("%d",&e1.age);
12 printf("n");
13 printf("Name and age of the employee: %s,%d",e1.name,e1.age);
14 return 0;
}
15
16
Ans:
1 #include<stdio.h>
2 void change(int,int);
int main()
3 {
4 int a=25,b=50;
5 change(a,b);
6 printf("The value assigned to a is: %d",a);
7 printf("n");
printf("The value assigned to of b is: %d",b);
8 return 0;
9 }
10 void change(int x,int y)
11 {
x=100;
12 y=200;
13 }
14
15
16
//Output
1
2 #include<stdio.h>
3 void change(int*,int*);
4 int main()
5 {
int a=25,b=50;
6 change(&a,&b);
7 printf("The value assigned to a is: %d",a);
8 printf("n");
9 printf("The value assigned to b is: %d",b);
10 return 0;
}
11 void change(int *x,int *y)
12 {
13 *x=100;
14 *y=200;
}
15
16
//Output
In case you are facing any challenges with these C Programming Interview Questions,
please write your problems in the comment section below.
getch(): reads characters from the keyboard but it does not use any buffers. Hence, data
is not displayed on the screen.
getche(): reads characters from the keyboard and it uses a buffer. Hence, data is
displayed on the screen.
//Example
1
2 #include<stdio.h>
3 #include<conio.h>
int main()
4
{
5 char ch;
6 printf("Please enter a character ");
7 ch=getch();
8 printf("nYour entered character is %c",ch);
printf("nPlease enter another character ");
9 ch=getche();
10 printf("nYour new character is %c",ch);
11 return 0;
12 }
13
//Output
//Example
1 #include<stdio.h>
2 #include<ctype.h>
3 int main()
{
4 char c;
5 c=a;
6 printf("%c after conversions %c", c, toupper(c));
7 c=B;
8 printf("%c after conversions %c", c, toupper(c));
9
//Output:
a after conversions A
B after conversions B
1
2 #include<stdio.h>
3 #include<stdlib.h>
int main()
4 {
5 int a,b;
6 for(a=1;a<=10;a++)
7 {
8 b=rand();
printf("%dn",b);
9 }
10 return 0;
11 }
12
//Output
1987384758
2057844389
3475398489
2247357398
1435983905
Ans: It is possible to create a new header file. Create a file with function prototypes that
need to be used in the program. Include the file in the ‘#include’ section in its name.
Ans: Memory Leak can be defined as a situation where programmer allocates dynamic
memory to the program but fails to free or delete the used memory after the completion
of the code. This is harmful if daemons and servers are included in the program.
1
2
3 #include<stdio.h>
4 #include<stdlib.h>
5 int main()
6 {
7 int* ptr;
int n, i, sum = 0;
8 n = 5;
9 printf("Enter the number of elements: %dn", n);
10 ptr = (int*)malloc(n * sizeof(int));
11 if (ptr == NULL)
12 {
printf("Memory not allocated.n");
13 exit(0);
14 }
15 else
16 {
printf("Memory successfully allocated using malloc.n");
17 for (i = 0; i<= n; ++i)
18 {
19 ptr[i] = i + 1;
20 }
21 printf("The elements of the array are: ");
for (i = 0; i<=n; ++i)
22 {
23 printf("%d, ", ptr[i]);
24 }
25 }
return 0;
26 }
27
28
29
//Output
In case you are facing any challenges with these C Programming Interview Questions,
please write your problems in the comment section below.
Ans: A local static variable is a variable whose life doesn’t end with a function call where
it is declared. It extends for the lifetime of the complete program. All calls to the function
share the same copy of local static variables.
1 #include<stdio.h>
2 void fun()
3 {
4 static int x;
5 printf("%d ", x);
x = x + 1;
6 }
7 int main()
8 {
9 fun();
fun();
10 return 0;
11 }
12
13
//Output
0 1
Q32. What is the difference between declaring a header file with < > and
” “?
Ans: If the Header File is declared using < > then the compiler searches for the header
file within the Built-in Path. If the Header File is declared using ” ” then the compiler will
search for the Header File in the current working directory and if not found then it searches
for the file in other locations.
Ans: We use Register Storage Specifier if a certain variable is used very frequently. This
helps the compiler to locate the variable as the variable will be declared in one of the CPU
registers.
Ans: x++; is the most efficient statement as it just a single instruction to the compiler
while the other is not.
Q35. Can I declare the same variable name to the variables which have
different scopes?
Ans: Yes, Same variable name can be declared to the variables with different variable
scopes as the following example.
1
2 int var;
void function()
3 {
4 int variable;
5 }
6 int main()
{
7 int variable;
8 }
9
Q36. Which variable can be used to access Union data members if the
Union variable is declared as a pointer variable?
Ans: Arrow Operator( -> ) can be used to access the data members of a Union if the
Union Variable is declared as a pointer variable.
Ans: 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
In case you are facing any challenges with these C Programming Interview Questions,
please write your problems in the comment section below.
auto
register
static
extern
Syntax:
1 (type_name) expression;
Ans:
1 #include&lt;stdio.h&gt;
2 void main()
3 {
4 if(printf("hello world")){}
}
5
//Output:
hello world
Q41. Write a program to swap two numbers without using the third
variable.
Ans:
1
2 #include&lt;stdio.h&gt;
3 #include&lt;conio.h&gt;
4 main()
{
5 int a=10, b=20;
6 clrscr();
7 printf("Before swapping a=%d b=%d",a,b);
8 a=a+b;
b=a-b;
9 a=a-b;
10 printf("nAfter swapping a=%d b=%d",a,b);
11 getch();
12 }
13
//Output
Before swapping a=10 b=20
After swapping a=20 b=10
Q42. How can you print a string with the symbol % in it?
Ans: There is no escape sequence provided for the symbol % in C. So, to print % we
should use ‘%%’ as shown below.
Ans: To print the above pattern, the following code can be used.
1 #include&lt;stdio.h&gt;
2 int main()
3 {
for(i=1;i&lt;=5;1++)
4 {
5 for(j=1;j&lt;=5;j++)
6 {
7 print("%d",j);
}
8 printf("n");
9 }
10 return 0;
11 }
12
13
Ans: The following program will help you to remove duplicates from an array.
#include &lt;stdio.h&gt;
1 int main()
2 {
3 int n, a[100], b[100], calc = 0, i, j,count;
4 printf("Enter no. of elements in array.n");
scanf("%d", &amp;n);
5
printf("Enter %d integersn", n);
6 for (i = 0; i &lt; n; i++)
7 scanf("%d", &amp;a[i]);
8 for (i = 0; i&lt;n; i++)
9 {
for (j = 0; j&lt;calc; j++)
10 {
11 if(a[i] == b[j])
12 break;
13 }
14 if (j== calc)
{
15 b[count] = a[i];
16 calc++;
17 }
}
18 printf("Array obtained after removing duplicate elementsn");
19 for (i = 0; i&lt;calc; i++)
20 {
21 printf("%dn", b[i]);
}
22 return 0;
23 }
24
25
26
27
28
29
//Output
Ans: 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.
1 int main()
2 {
int array[100], n, i, j, swap;
3 printf("Enter number of elementsn");
4 scanf("%d", &amp;n);
5 printf("Enter %d Numbers:n", n);
6 for(i = 0; i&lt;n; i++)
scanf("%d", &amp;array[i]);
7 for(i = 0 ; i&lt;n - 1; i++)
8 {
9 for(j = 0 ; j &lt; n-i-1; j++) { if(array[j]&gt;array
10 {
11 swap=array[j];
array[j]=array[j+1];
12 array[j+1]=swap;
13 }
14 }
15 }
printf("Sorted Array:n");
16 for(i = 0; i &lt; n; i++)
17 printf("%dn", array[i]);
18 return 0;
19 }
20
21
22
23
Ans: Round-robin Algorithm is one of the algorithms employed by process and network
schedulers in computing in order to evenly distribute resources in the system.
#include&lt;stdio.h&g
1
2 int main()
3 {
4 int i, limit, total = 0, x, counter =
5 int wait_time = 0, turnaround_time = 0, arrival_time
6 float average_wait_time, average_tu
printf("nEnter Total Number of Pr
7 scanf("%d", &amp;limi
8 x = limit;
9 for(i = 0; i&lt;limit;
10 {
printf("nEnter Details of Proces
11 printf("Arrival Time
12 scanf("%d", &amp;arriva
13 printf("Burst Time:
14 scanf("%d", &amp;burst
15 temp[i] = burst_time
}
16
17 printf("nEnter Time Quantum
18 scanf("%d", &amp;time_qu
19 printf("nProcess IDttBurst Timet Turnaround
20 for(total = 0, i = 0; x !=
21 {
if(temp[i] &lt;= time_quantum &amp;&
22 {
23 total = total + t
24 temp[i] = 0
counter = 1
25 }
26 else if(temp[i]&
27 {
28 temp[i] = temp[i] - t
total = total + tim
29 }
30 if(temp[i] == 0 &amp;&am
31 {
32 x--;
33 printf("nProcess[%d]tt%dtt %dttt %d", i + 1, burst_time[i],
burst_time[i]);
34 wait_time = wait_time + total - arriv
35 turnaround_time = turnaround_time +
36 counter = 0
37 }
if(i == limit - 1
38 {
39 i = 0;
40 }
41 else if(arrival_time[i + 1] &a
42 {
i++;
43 }
44 else
45 {
46 i = 0;
47 }
}
48
49 average_wait_time = wait_time *
50 average_turnaround_time = turnaround_t
51 printf("nnAverage Waiting Time:t%f", av
52 printf("nAvg Turnaround Time:t%fn", avera
return 0;
53 }
54
55
56
57
58
59
60
61
62
63
64
//Output
In case you are facing any challenges with these C Programming Interview Questions,
please write your problems in the comment section below.
Q48. Which structure is used to link the program and the operating
system?
Q49. What are the limitations of scanf() and how can it be avoided?
Ans: The differences between macros and functions can be explained as follows:
Macro call replaces the templates with the expansion in a literal way.
The Macro call makes the program run faster but also increases the program
size.
Macro is simple and avoids errors related to the function calls.
In a function, call control is transferred to the function along with arguments.
It makes the functions small and compact.
Passing arguments and getting back the returned value takes time and makes
the program run at a slower rate.
Q51. Suppose a global variable and local variable have the same name. Is
it is possible to access a global variable from a block where local
variables are defined?
Ans: No. It is not possible in C. It is always the most local variable that gets preference.
With this, we come to an end of this “C Programming Interview Questions” article. I hope
you have understood the importance of C Programming.
Now that you have understood the basics of Programming in C, check out
the training provided by Edureka on many technologies like Java, Spring, and many
more, a trusted online learning company with a network of more than 250,000 satisfied
learners spread across the globe
Got a question for us? Mention it in the comments section of this “C Programming
Interview Questions” blog and we will get back to you as soon as possible.