This is an article prepared for you to answer all the frequently asked questions (short or long) in C and more. This listed FAQ is also prepared for interview questions that you may prepare through it. Not only about C but also about the compilers and headers used, etc.
Although right now only a few questions with solutions are presented but will be extended or more questions will be added in upcoming months. So stay connected to simple2code.com.
Let us begin.
1. What is Acronym for ANSI and ASCII?
ANSI:-American National Standards Institute
ASCII:-American Standard Code for Information Interchange
2. What is an Automatic storage Class?
A variable defined within a function or block with an auto specifier belongs to the automatic storage class. Auto variables can only be accessed within the block/function they have been declared and not outside them (which defines their scope).
3. C is derived from which language?
4. Who invented C ?
Developed at AT&T’s Bell Laboratories(USA,1972) Designed by Dennis Ritchie. Its features were derived from an earlier language class “B“, which according to Ken Thompson was a stripped-down version of the BCPL programming language.
5. What is low, middle and High level language? Which one is C?
There are three types of language: High Level, Middle Level & Low Level.
- High-level languages are user-oriented, giving faster development of programs, an example is BASIC.
- Low-level languages are machine-oriented; they provide faster execution of programs.
C is a middle-level language because it combines the best part of high-level language with low-level language. It is both user and machine-oriented and provides infinite possibilities.
6. State the Difference between Compiler and Interpreter?
|The compiler translates the entire program to machine code at once.||The interpreter translates line by line process.|
|It generates intermediate code, called the object code or machine code.||It does not generate object code or machine code.|
|More difficult to debug compared to Interpreter as all errors are shown at a time.||Easier to debug since execution will stop if the error is found in a particular line.|
|It takes a large amount of time to analyze the source code but the overall execution time is comparatively faster.||It takes less amount of time to analyze the source code but the overall execution time is slower.|
|Takes more memory compared to Interpreter as Intermediate code is generated||Takes Less Memory(Memory Efficient) as Intermediate code is not generated|
|Example: C, C++, COBOL, etc.||Example: BASIC, Ruby, Python, etc.|
7. What character is the end of a string?
The character used for ending a string is “\0”.
Then Even though the string length is 11 it is ended with ‘\0’ i.e Hello\0. It indicates the end of a string.
8. What is conio.h and getch() and clrscr()?
- “conio” means console input and output.
- getch() is defined in “conio.h”. getch() is used to freeze the console screen for user input. It will read a character as input.
- Clrscr() is used to clear the screen while displaying the output.
At present we are using compilers that will show output after running a program without closing the console so no need to use
getch(). Even though, the
clrscr() is not present at beginning of the program and
getch() at the end of the program, the program automatically clears the previous output so there is no need for
9. What is Dangling Pointer?
A dangling pointer is a pointer that has an invalid memory location. Usually, this happens in such situations where we free memory allocated to pointer from memory location then it is pointing to an invalid memory location.
10. What are the modes in files?
|“r”||Opens the file in reading mode. If the file is found then the file is loaded into memory and the pointer is set to the first character of the file. If the file doesn’t exist or cannot be opened it returns NULL.|
|“w”||If the file exists then its content is overwritten. If the file doesn’t exist then it will create a new file and write the data into it. If the file can’t be opened in any case it will return NULL.|
|“a”||Used to add new content at the end of the file. If the file exists then the new data/content is appended at the end of the file. In this case, the file is loaded into memory, and the pointer is set to the last character of the file.|
If the file does not exist then a new file is created.
If in case of file can’t be opened then it returns NULL.
|“r+”||Opens the existing files in reading and writing mode. If the file can’t be opened then it returns NULL.|
|“w+”||Opens a new file in reading and writing mode if the file does not exist.|
If the file exists the content is overwritten.
If the file can’t be opened then it returns NULL.
|“a+”||Opens file in reading and appending mode if the file exists.|
If the file can’t be opened returns NULL.Cannot modify existing data, but can append the data at the end of the file.
11. List the files that are generated after running C program?
- When you save source code “.c” file is generated.
- When you compile the C program then the “.o” file is generated which means object file.
- On running the program “.exe” file is generated which means an executable file.
12. When to use for loop, while loop, and do-while loop?
- for loop: is a preferred statement that is to be executed for a fixed or known number of times.
- while loop: While loop is used to repeat a section of code an unknown number of times until a specific condition is met
- do-while loop: When the loop has to be executed at least one time.
13. What are header files?
Header files contains predefined keywords like printf, scanf, main() etc in stdio.h. So including them with #include <stdio.h> makes us to use them in our program. Their functionality(i.e printf, scanf, main()) is defined in stdio.h header file. Similarly math.h, conio.h etc.
14. What are actual parameters(arguments) and formal parameters?
Parameters in calling function are called actual parameters or Arguments Parameters in Called functions are called formal parameters.
15. What are comments and why we use them and In what way they will affect the program
The comment starts with’ /*’ and ends with ‘*/’. Comments are not mandatory but still, it’s a good practice if you use them, it improves the readability of the code. A program can have any number of comments.
16. what is d in %d and i in %i, x in %x, o in %obtain
- %d represents decimal(base 10)
- i represents integer
- x represents hexadecimal(base 16)
- o represents Octal(base 8)
17. What is External Storage Class?
Extern stands for external storage class. The principal use of extern is to specify that a variable is declared with external linkage elsewhere in the program. In general, it is used to declare a variable to be used in a module that is not the one in which the corresponding variable is defined
18. What is ‘f’ in printf or scanf?
‘f’ in printf or scanf indicates a Formatted Specifier.
19. What is Far Pointer?
A pointer that can access all 16 segments of RAM
20. Why i++ execution is faster than i+1?
Since i++ requires only one instruction in assembly language while compiling but i+1 requires more than one instruction
21. Is FILE s built-in datatype?
No File is not a built-in datatype but it is a structure defined in stdio.h
More will be added soon.
String Pattern Programs in C
Java Program to Find pair of Integers in Array whose sum is given Number
Program to Print Diamond Alphabet Patterns in C
Half Diamond Pattern in C using Alphabets
Half Pyramid of Alphabets in C