C Language interview QA

List of Top C Programming Language Interview Questions and Answers for freshers and experienced are below:


1) Who invented C Language?
-->  Dennis Ritchie in 1972 developed a new language by inheriting the features of both BCPL and B and adding additional features. He named the language as just C.

2) Who invented B Language?
-->  Ken Thomson at AT&T Bell Labs developed a language and named it B. Even the B language was found to have some short comings to support development of both business applications and system software.

3) Who invented BCPL Language?
-->  Basic Combined Programming Language(BCPL) was developed by Martin Richards, Cambridge university.

4) Why C Language?
-->  C is one of the high level languages. It is a general purpose language, which means it can be used to write programs of any sort.

5) What are the features of C Langauges?
=> In C one can write programs like that of high level languages as in COBOL, BASIC, FORTRAN etc. as well as it permits very close interaction with the inner workings of the computer.
=> It is a general purpose programming language. It is usually called system programming language but equally suited to writing a variety of applications.
=> It supports various data types
=> It follows the programming style based on fundamental control flow constructions for structured programming
=> Functions may be predefined or user defined and they may return values of basic types, structures, unions or pointers.


6)What are the advantages of c language?
=> Easy to write
=> Rich set of operators and functions that are built–in
=> Support for bit–wise operation
=> Flexible use of pointers
=> Direct control over the hardware
=> Ability to access BIOS/DOS routines
=> Interacting using Interrupts
=> Ability to write TSR programs
=> Ability to create .COM files
=> Ability to create library files (.LIB)
=> Ability to write interface programs
=> Incorporating assembly language in C program

7) What are the disadvantages of c language?
=> C is considered difficult to learn
=> Because of its conciseness, the code can be difficult to follow
=> It is not suited to applications that require a lot of report formatting and data file manipulation

8) What are the salient features of c languages?
=> The following are the salient features of C language are :
=> C is called a middle level language
=> C supports structured design approach
=> C is extensible
=> C is rich in data types and operators
=> C is portable

9) What is a header file?
-->  Header files provide the definitions and declarations for the library functions. Thus, each header file contains the library functions along with the necessary definitions and declarations. For example, stdio.h, math.h, stdlib.h, string.h etc.

10) What is character set?
-->  Character set is the set of characters allowed and supported in the programming language.

Generally a program is a collection of instructions, which contain groups of characters. Only a limited set of characters is allowed to write instructions in the program.


11) What is C token?
-->  The smallest individual units of a C program are known as tokens.

12) List the different types of C tokens?
=> Constants
=> Identifiers
=> Keywords
=> Operators
=> Special symbols
=> Strings

13) What is a string?
-->  A string is a sequence of characters ending with NUL. It can be treated as a one–dimensional array of characters terminated by a NUL character.

14) What are qualifiers?
-->  Qualifiers or modifiers are identifiers that may precede the scalar data types (except float) to specify the number of bits used for representing the respective type of data in memory. The qualifiers in C are short, long, signed, and unsigned.

15) What is a function?
-->  A function is a set of statements to perform a specific task.

16) What is a constant?
-->  A constant is a value that does not change during the program execution. A constant used in C does not occupy memory.

17) What are the different types of constants?
=> There are five types of constants. They are :
=> Integer constants
=> Floating point constants
=> Character constants
=> String literals
=> Enumeration constants

18) What is variable?
-->  An identifier is used to identify and store some value. If the value of the identifier is changed during the execution of the program, then the identifier is known as variable.

19) What are the rules for the identifier?
=> The first character must be an alphabet or underscore (_)
=> Digits may be included in the variable
=> The maximum number of characters in a word are 32 (It may vary depending upon the platform)
=> No other special characters are allowed.

20) What are global variables?
-->  Global Variables are those, which are required to be acccessed by all the functions defined after their declaration. So, the variables declared before the main {) can be acccessed by all the functions, which follow their declaration.

21) What is the purpose of main( ) function?
-->  The function main( ) invokes other functions within it.It is the first function to be called when the program starts execution.
- It is the starting function
- It returns an int value to the environment that called the program
- Recursive call is allowed for main( ) also.
- It is a user-defined function
- Program execution ends when the closing brace of the function main( ) is reached.
- It has two arguments 1)argument count and 2) argument vector (represents strings passed).
- Any user-defined name can also be used as parameters for main( ) instead of argc and argv

22) Why n++ executes faster than n+1?
-->  The expression n++ requires a single machine instruction such as INR to carry out the increment operation whereas, n+1 requires more instructions to carry out this operation.

23) What will the preprocessor do for a program?
-->  The C preprocessor is used to modify your program according to the preprocessor directives in your source code. A preprocessor directive is a statement (such as #define) that gives the preprocessor specific instructions on how to modify your source code.

The preprocessor is invoked as the first part of your compiler program’s compilation step. It is usually hidden from the programmer because it is run automatically by the compiler.

The preprocessor reads in all of your include files and the source code you are compiling and creates a preprocessed version of your source code. This preprocessed version has all of its macros and constant symbols replaced by their corresponding code and value assignments.

If your source code contains any conditional preprocessor directives (such as #if), the preprocessor evaluates the condition and modifies your source code accordingly.

24) What is the benefit of using const for declaring constants?
-->  The benefit of using the const keyword is that the compiler might be able to make optimizations based on the knowledge that the value of the variable will not change. In addition, the compiler will try to ensure that the values won’t be changed inadvertently. Of course, the same benefits apply to #defined constants.

The reason to use const rather than #define to define a constant is that a const variable can be of any type (such as a struct, which can’t be represented by a #defined constant). Also, because a const variable is a real variable, it has an address that can be used, if needed, and it resides in only one place in memory

25) Is it better to use a macro or a function?
-->  The answer depends on the situation you are writing code for. Macros have the distinct advantage of being more efficient (and faster) than functions, because their corresponding code is inserted directly into your source code at the point where the macro is called.

There is no overhead involved in using a macro like there is in placing a call to a function. However, macros are generally small and cannot handle large, complex coding constructs. A function is more suited for this type of situation. Additionally, macros are expanded inline, which means that the code is replicated for each occurrence of a macro. Your code therefore could be somewhat larger when you use macros than if you were to use functions.

Thus, the choice between using a macro and using a function is one of deciding between the tradeoff of faster program speed versus smaller program size. Generally, you should use macros to replace small, repeatable code sections, and you should use functions for larger coding tasks that might require several lines of code.

26) What are the standard predefined macros?
-->  The ANSI C standard defines six predefined macros for use in the C language:

Macro Name Purpose::
_ _LINE_ _ Inserts the current source code line number in your code.
_ _FILE_ _ Inserts the current source code filename in your code.
_ _ Inserts the current date of compilation in your code.
_ _TIME_ _ Inserts the current time of compilation in your code.
_ _STDC_ _ Is set to 1 if you are enforcing strict ANSI C conformity.
_ _cplusplus Is defined if you are compiling a C++ program.

Post a Comment

 
Top