C-INTERVIEW (Waht Is What)
C-INTERVIEW (Waht Is What)
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: 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: C introduced many core concepts and data structures like arrays, lists,
functions, strings, etc. Many languages designed after C are designed on the
basis of C Language. Hence, it is considered as the mother of all languages.
Q14. Mention the features of C Programming Language.
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,
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.
Syntax:
Syntax:
Syntax:
Syntax:
1free(ptr);
Ans: We cannot use & on constants and on a variable which is declared using
the register storage class.
Q24. Write a simple example of a structure in C Language
1struct employee
2{
3 char name[10];
4 int age;
5}e1;
6int main()
7{
8 printf("Enter the name");
9 scanf("%s",e1.name);
10 printf("n");
11 printf("Enter the age");
12 scanf("%d",&e1.age);
13 printf("n");
14 printf("Name and age of the employee: %s,%d",e1.name,e1.age);
15 return 0;
16}
Ans:
Ans: Both the functions are designed to read characters from the keyboard and
the only difference is that
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#include<stdio.h>
2#include<conio.h>
3int main()
4{
5 char ch;
6 printf("Please enter a character ");
7 ch=getch();
8 printf("nYour entered character is %c",ch);
9 printf("nPlease enter another character ");
10 ch=getche();
11 printf("nYour new character is %c",ch);
12 return 0;
13}
//Output
//Example
1#include<stdio.h>
2#include<ctype.h>
3int main()
4{
5 char c;
6 c=a;
7 printf("%c after conversions %c", c, toupper(c));
8 c=B;
9 printf("%c after conversions %c", c, toupper(c));
//Output:
a after conversions A
B after conversions B
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: 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>
2void fun()
3{
4 static int x;
5 printf("%d ", x);
6 x = x + 1;
7}
8int main()
9{
10 fun();
11 fun();
12 return 0;
13}
//Output
01
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: 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.
1int var;
2void function()
3{
4 int variable;
5}
6int main()
7{
8 int variable;
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.
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
Ans: 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.
Syntax:
1(type_name) expression;
Q40. Write a C program to print hello world without using a semicolon (;).
Ans:
1#include<stdio.h>
2void 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#include<stdio.h>
2#include<conio.h>
3main()
4{
5 int a=10, b=20;
6 clrscr();
7 printf("Before swapping a=%d b=%d",a,b);
8 a=a+b;
9 b=a-b;
10 a=a-b;
11 printf("nAfter swapping a=%d b=%d",a,b);
12 getch();
13}
//Output
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: 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.
1int main()
2{
3 int array[100], n, i, j, swap;
4 printf("Enter number of elementsn");
5 scanf("%d", &amp;n);
6 printf("Enter %d Numbers:n", n);
7 for(i = 0; i&lt;n; i++)
8 scanf("%d", &amp;array[i]);
9 for(i = 0 ; i&lt;n - 1; i++)
10 {
11 for(j = 0 ; j &lt; n-i-1; j++) { if(array[j]&gt;array[j+1])
12 {
13 swap=array[j];
14 array[j]=array[j+1];
15 array[j+1]=swap;
16 }
17 }
18 }
19 printf("Sorted Array:n");
20 for(i = 0; i &lt; n; i++)
21 printf("%dn", array[i]);
22 return 0;
23}
Q47. Which structure is used to link the program and the operating
system?
Q48. What are the limitations of scanf() and how can it be avoided?
Q50. 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.