C interview

C language- TechClinch- interview preparation- interview questions- answers- job
C language- TechClinch

 

Explain the features of variables defined in the register storage class.

• The data is stored in the CPU registers.
 • Default initial value taken by the variable defined in this class is garbage value.
 • It is local to the block in which the variable is defined.
 • The function is active till the control remains within the block in which variable is defined.
 • The value stored in this register is always accessed at a faster rate than value stored in memory.
 • Example: loop counters.

What is a macro?

• It is a preprocessor directive used to change the value of constant at all places in a program by changing the directive.
 • It uses the #define directive to define the value of constant before the main program.
 • The macro templates are always named in capital letters.
 • Example: #define UPPER 25
 main( )
 {
 int a=0;
 a = a+ UPPER;
 }
 Here the variable UPPER is defined and is assigned value 25.
 • UPPER is the macro template and 25 is its expansion and this 25 can be changed easily.

Differentiate between the macros and the functions.

• Macro call replaces the templates with the expansion in a literal way.
 • 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 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 slower rate.

How can one file be included in another file?

• To include one file to another a preprocessor directive called file inclusion is used .
 • It causes the entire contents of filename to be inserted into the source code at that point in the program.
 • It is used when very large programs are present and the code is subdivided into different files containing the set of related functions.
 • Syntax : #include “filename” or #include <filename>
 • Include search path in list of directories that would be searched for file being included.

What is #undef ?

• Sometimes it is desirable to cause a defined name to become undefined so #undef is used.
 • It mainly undefine the macro which has been earlier #defined and represented as #undef macro template.
 • Example: #undef PENTIUM
 • This statement causes the definition of PENTIUM to be removed from the system.

Explain the # pragma directive.

• This is a preprocessor directive that can be used to turn on or off certain features.
 • It is of two types #pragma startup, #pragma exit and pragma warn.
 • #pragma startup allows us to specify functions called upon program startup.
 • #pragma exit allows us to specify functions called upon program exit.
 • #pragma warn tells the computer to suppress any warning or not.

List some of the escape sequences used in the c language.

• \t moves the curser to the next tab stop.
 • \b moves the curser one position to the left of its current position.
 • \r moves the curser to the beginning of the line in which it is currently placed.
 • \a alerts the user by sounding the speaker inside the computer.
 • \f is the form speed which advances the computer stationary attached to printer to top of next page.

Which structure is used to link the program and the operating system ?

• The structure used to link the operating system to a program is file.
 • File is defined in the header file “stdio.h”(standard input/output header file).
 • It contains the information about file being used, its current size and its location in memory.
 • It contains character pointer that points to character that is being opened.
 • Opening a file establishes a link between the program and operating system about which file is to be accessed.

What are command line arguments.

• The arguments that we pass on to main ( ) at the command prompt are called command line arguments.
 • It has two arguments called argc and argv.
 • argv is an array of pointers to string and argc is an int whose whole value is equal to number of strings to which agrv points.
 • Here the address of first string is stored in the argv[0] and of second is stored in argv[1].
 • argc is set of number of strings given on command prompt.

What are the limitations of scanf and how can it be avoided?

• scanf cannot work with the string of characters.
 • It is not possible to enter a multiword string into a single variable using scanf.
 • To avoid this the gets( ) function is used.
 • It gets a string from the keyboard and is terminated when enter key is pressed.
 • Here the spaces and tabs are acceptable as part of the input string.

What is the difference between goto and long jmp( ) and setjmp()?

A goto statement implements a local jump of program execution, and the longjmp() and setjmp() functions implement a nonlocal or far jump of program execution. To use the goto statement, you give it a labeled position to jump to. This predefined position must be within the same function.
 When your program calls setjmp(), the current state of your program is saved in a structure of type jmp_buf. Later, your program can call the longjmp() function to restore the program's state as it was when you called setjmp(). Unlike the goto statement, the longjmp() and setjmp() functions do not need to be implemented in the same function.

What is Dangling pointer?

Ans: Dangling Pointer is a pointer that doesn’t point to a valid memory location. Dangling pointers arise when an object is deleted or deallocated, without modifying the value of the pointer, so that the pointer still points to the memory location of the deallocated memory

Difference between #define and const in C?

#define is a pre-processor directive. Things defined by #define are replaced by the pre-processor before compilation begins.
const variables are actual variables like other normal variable.
The big advantage of const over #define is type checking. We can also have poitners to const variables, we can pass them around, typecast them and any other thing that can be done with a normal variable. One disadvantage that one could think of is extra space for variable which is immaterial due to optimizations done by compilers.
In general const is a better option if we have a choice. There are situations when #define cannot be replaced by const. For example, #define can take parameters . #define can also be used to replace some text in a program with another text

Recursive data structures are almost always implemented with memory from

-stack
-heap 
-processor
-RAM
ANS: Heap

What is mean by inverted file?

It locates information about data in small files that are maintained apart from actual data record.

Explain spaghetti programming.

- Spaghetti programming refers to codes that tend to get tangled and overlapped throughout the program. 
- It makes a program complex and analyzing the code becomes difficult. It usually happens due to the lack of work experience on developer's part.

Differentiate between functions getch() and getche().

- Both functions accept a character input value from the user. 
- When getch() is used, the key that was pressed will not appear on the screen. It is automatically captured and assigned to a variable. 
- While when getche() is used, the key that was pressed by the user appears on the screen and is assigned to a variable.

What is “Bus error”?

A bus error indicates an attempt to access memory in an illegal way,perhaps due to an unaligned pointer

What is size of void pointer?

Size of any type of pointer in c is independent of data type which is pointer is pointing i.e. size of all type of pointer (near) in c is two byte either it is char pointer, double pointer, function pointer or null pointer. Void pointer is not exception of this rule and size of void pointer is also two byte.

What is near pointer?

A near pointer is 16 bits long. It uses the current content of the CS (code segment) register (if
the pointer is pointing to code) or current contents of DS (data segment) register (if the pointer is pointing to data) for the segment part, the offset part is stored in a 16 bit near pointer. Using near pointer limits the data/code to 64kb segment.

 

Leave a Reply

Your email address will not be published. Required fields are marked *