Top 43 “C” Interview Question

-: “C” Interview Question :-
-: “C” साक्षात्कार प्रश्न :-

1)  How do you construct an increment statement or decrement statement in C?

-> It can be done in two ways- a)Using increment or deccrement operator. For example- if ‘x’ is an integer variable,x++ means the value of x will be incremented by 1. if x=1, x++ means the value of x is 2. In case of decrement operator,if x=5,x– means the value of x is 4. b)Another way to increment or decrement is simply adding or subtracting integer value to a variable. For example if x=5, we can increment it like x=x+1 or decrement it like x=x-1, so the value of x will be 6 and 4 respectively.

2) Some coders debug their programs by placing comment symbols on some codes instead of deleting it. How does this aid in debugging?

-> It’s helpful when you are finding a specific error generated in the coding section.Commenting the code is a good practice.Sometimes commenting a part helps the programmer to find out the error easily.We can comment C codes with //(sigle line comment),/**/(multiple line comment). It doesn’t read by the compiler.

3) What is the equivalent code of the following statement in WHILE LOOP format?

-> for (a=1; a<=100; a++)printf (“%dn”, a * a);
Answer:In C,a=1;while (a<=100) {printf (“%dn”, a * a);a++;}

4) What is spaghetti programming?

-> Spaghetti is kind of programming where the control of the program jumps from one place to another. This programming uses a lots of GOTO statements within it.It makes a program more critical to understand and it denies the natural flow of the code in the program. Most of the OOP’s languages has reduced the prevalence of Spaghetti code.

5) In C programming, how do you insert quote characters (‘ and “) into the output screen?

-> In C programming every symbol have their unique identity and ASCII value. As ‘ and ” are a special character, before using these you have to be carefull. If you want these to be printed like a siple charater in a statement then just use format specifiers before these to indicate as a simple printable charcter. Example- ‘ will print single quote and ” will print double quote.

6) What is the use of a ‘?�’ character?

-> ‘�’ is used to refer a null value. It is often used at the end of an array of character i,e string to indicate the termination of array.It holds a nothing,not even 0.

7) What is the difference between the = symbol and == symbol?

-> In C programming, ‘=’ is an assignment operator and ‘==’ is a relational operator. This assignment operator is used to assign or initialize a variable like x=5. Where 5 is stored in x variable. The relational == operator is used to compare between two variables’ value. Example- x==y, it will compare the value of x with the value of y.

8) Which of the following operators is incorrect and why? ( >=, <=, <>, ==)

-> Here <> is incorrect. It represents ‘not equal to’ whereas in C programming this symbol has no meaning ,even in C ‘not equal to’ is represented by ‘!=’ operator.

9) Can the curly brackets { } be used to enclose a single line of code?

-> It is not necessary to use {} brackets to enclose a single line of code.Basically this effects when a set of statements has to be executed together in conditional statements like if….else statements,loops. But to some programmers use this {} brackets to enclose the single statement in order to maintain a good practice and a proper way to reperesent them clearly.

10) What are header files and what are its uses in C programming?

-> Header files are a collection of functions. They also known as library files.These files help us by providing variety of functions without knowing the exact definations of the functions. The header files holds the definations and prototypes of some predefined functions and we just call them in our program where it is needed. Example- we use ‘printf()’ and ‘scanf()’ which are predefined in ‘stidio.h’

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

-> No.An “int” data type has a range from -32768 to +32767 for storing value. As 32768 is out of this range,it can not store this value.

12) Can two or more operators such as n and t be combined in a single line of program code?

-> Basically t and n are known as escape sequence in C programming and n means new line and t means tab. So we can use them in a single line of code. Example- printf(“HellontWorld”); It will print ‘Hello’ in the first line and in the next new line it will print a tab and then ‘World’.

13) Why is it that not all header files are declared in every C program?

-> It depends on what types of function you need in your program.If you need to print anything to the output string then you have to include stdio.h header files in your program. If you need to do any mathematical operations then you have to include math.h header files. Including all header file to any program will cause a heavy load to your program and it’s not a very good practice.

14) When is the ?void? keyword used in a function?

-> ‘void’ is used to indicate the empty value. We often see ‘void’ keyword is used before a function defination. It indicates that the function will not return any value. If we need to return a value then the ‘void’ keyword will be replaced by the data type of the retuned value. Example- we can use int main() instead of void main() to indicate that it will return integer value.

15) What are compound statements?

-> Compound statements often known as block.It appears in the body of another statements using {} curly braces. Unlike other statements it doesn’t end with a semicolon. Example- Writting a if condition or a loop using {} with a random statements within it, is a compound statement.

16) Write a loop statement that will show the following output:

1

12

123

1234

12345

Answer: The logic to print this pattern in C will be-
for (a=1; a<=5; i++) {for (b=1; b<=a; b++)printf(“%d”,b);printf(“n”);}

17) What is wrong in this statement?  scanf(?%d?,what number);

-> This is a logical error. Here Ampersand(in C known as ‘address of’ operator) is missing before the variable name ‘whatnumber’. It means the value which is put by the user will be store in the address of the variable ‘whatnumber’.

18) How do you generate random numbers in C?

-> It can be implemented by a command rand(). If you define a variable x as the interger in type then x=rand() will generate random value in the program.

19) What could possibly be the problem if a valid function name such as tolower() is being reported by the C compiler as undefined?

->This kind of problem occurs when you do not mention the header properly. You should check if the ‘#include’ is properly maintained in the program or not.

20) What does the format %10.2 mean when included in a printf statement?

-> It indicates the decimal number with 2 decimal places after the deccimal point and 10 decimal places before the the decimal point to represent the actual value.If the decimal number has less than the number of the decimal digits, it will be filled with 0 upto 10 where 0 will not be printed.

21) What is wrong with this statement? my Name = “?Robin”?;

-> “Robin” represents a string value where we can not assign this string to a normal variable. Either it has to be an array of characters or it can be represented as strcpy(my name,”Robin”);

22) How do you determine the length of a string value that was stored in a variable?

->It can be calculated by a string function named as strlen(). Consider a variable ‘name’ which hold a string value ‘Hello’. Now if we write int x=strlen(name); it will store the length in integer i.e 5 in x.

23) Is it possible to initialize a variable at the time it was declared?

->Yes. It is possible. Example- if you declare int x=5; it describes two things-the variable defination i.e x is an integer type of variable and it stores integer value 5 at the same time.

24) What are the different file extensions involved when programming in C?

-> In C programming, header files have their extension .h, the source code has the extention of .c and when the source code is compiled it creates a file with .obj to indicate the object extension and an executable file with the .exe extention name.

25) What are reserved words?

-> Reserved words are special keywords which have different purposes to use in the programming. Those words are part of the standard libarary in C. These can’t be used as a variable name in the program. Example- int,void,return,array,if,for,while etc.

26) What are linked list?

-> Linked list is used for utilize the memory for storage. In C, linked list are created using pointer where each node is connected with other nodes.

27) What are binary trees?

-> A binary tree, in C, is implemented using linked list. Here every node has two pointers- left and right. To add or remove from a tree list there is a certain method.Basically linked list forms a tree like structire which is called Binary tree.

28) Not all reserved words are written in lowercase. TRUE or FALSE?

-> False. All reserved keywords are written in lowercase letters.Remember C is a case sensitive.

29) What is wrong with this program statement? void = 10;

->“Void” is a reserved keyword and we can not use it as a variable name in program.

30) Is this program statement valid? INT = 10.50;

-> Yes. Here ‘INT’ is in upper case and ‘int’ which is a reserved word are two different things. The compiler will take ‘INT’ as a variable name because it has different ASCII value than ‘int’.

31) What is a newline escape sequence?

->Newline escape sequence is represented by ‘n’ in C programming. It is used to print a output in a new line. Example- printf(“HellonnWorld!”); will print ‘Hello’ in the first line and after two line will print the ‘World!’ on the output screen.

32) What is output redirection?

-> Output rediraction is basically used to save the output result in a file by not to showing it in the output screen.

33) What is the difference between functions abs() and fabs()?

-> These two functions performs the same task. abs() is used to get absolute value for integer and fabs() is used to get the floating value.

34) Write a simple code fragment that will check if a number is positive or negative.

-> Answer: In C programming,
If (num>=0)printf(“number is positive”);elseprintf (“number is negative”);

35) What does the function toupper() do?

-> toupper() converts a lowercase letter to uppercase letter. It takes only one letter at a time. It cann’t convert a string.

36) Which function in C can be used to append a string to another string?

-> ‘strcat’ can be used to append a string to another string. It concatenates two strings. Example- strcat(‘hello’,’World’); will give the out put as ‘helloWorld’.

37) Do these two program statements perform the same output?

1) scanf(?%c?, &letter);  2) letter=getchar()->Yes.These two statements are doing the same task.

38) What is the difference between text files and binary files?

->A text file is readable to humans but a binary file is readable by computers only. Binary files are written using only 0 and 1.

39) Is it possible to create your own header files?

->Yes,it can be possible. To do that first ypu have to create a header file with a name and then you have to call it in the beginning of the program like #include your_customized_header.

40) What is dynamic data structure?

->The memory allocation for storing data is an important part in the programming. To do so we use dynamic data structure and reduce the wastage of memory.

41) The % symbol has a special use in a printf statement. How would you place this character as part of the output on the screen?

-> To print this persantage(%) on the output screen simply use double persantage(%%) to print one.Example-printf(“success 90%%”); will print ‘success 90%’.

42) What are the advantages and disadvantages of a heap?

-> The disadvantage of heap is that it is slow for storing data. But it is flexible in use.To overcome this slowness it needs an algorithm better structured and implemented.

43)Why ‘for’ loop is called a entry control loop?

-> In case of for loop, the condition is satisfied first then the statements get executed.Due to entry time checking, for loop is called entry control loop.


♦ Important Links (महत्वाच्या लिंक्स) ♦

Government Jobs.
Private Jobs.
सर्व परीक्षांच्या सराव प्रश्नपत्रिका (Previous Question Papers).
परीक्षेचे निकाल (Results).
परीक्षा प्रवेशपत्र (Hall Tickets).
MPSC भरती.
Bank Jobs.
Mega Bharti.
Current Affairs ((चालू घडामोडी).
रोजगार मेळावा (Jobs Fairs).

🔎जिल्हा नुसार जाहिराती📲

अहमदनगर अकोला अमरावती औरंगाबाद भंडारा बुलढाणा
चंद्रपुर धुले गढ़चिरौली गोंदिया हिंगोली जलगांव
जालना कोल्हापुर लातूर मुंबई नागपुर नांदेड़
नंदुरबार नाशिक उस्मानाबाद पालघर परभानी पुणे
रायगढ़ रत्नागिरि सांगली सातारा सिंधुदुर्ग सोलापुर
ठाणे वर्धा वाशिम यवतमाल बीड  

🎓शिक्षणानुसार जाहिराती💼

७ वी (7th) दहावी (SSC) बारावी (HSC) डिप्लोमा आय.टी.आय पदवी
पदव्युत्तर शिक्षण बी.एड एम.एड एल.एल.बी / एल.एल.एम बीएससी एमबीए
बीसीए एमसीए बी.कॉम एम.कॉम GNM/ANM एमएससी
बी.फार्म एम.फार्म बी.ई एम.ई BAMS/BHMS एम.बी.बी.एस / एम.डी
बी.टेक एम.टेक MS-CIT