• +91 9723535972
  • info@interviewmaterial.com

C Interview Questions and Answers

C Interview Questions and Answers

Question - 101 : - How are portions of a program disabled in demo versions?

Answer - 101 : - If you are distributing a demo version of your program, the preprocessor can be used to enable or disable portions of your program. The following portion of code shows how this task is accomplished, using the preprocessor directives #if and #endif: int save_document(char* doc_name) { #if DEMO_VERSION printf(Sorry! You can’t save documents using the DEMO version of this programming); return(0); #endif ... }

Question - 102 : - What is modular programming?

Answer - 102 : - If a program is large, it is subdivided into a number of smaller programs that are called modules or subprograms. If a complex problem is solved using more modules, this approach is known as modular programming.

Question - 103 : - How can you determine the maximum value that a numeric variable can hold?

Answer - 103 : - For integral types, on a machine that uses two’s complement arithmetic (which is just about any machine you’re likely to use), a signed type can hold numbers from 2(number of bits 1) to +2(number of bits 1) 1. An unsigned type can hold values from 0 to +2(number of bits) 1. For instance, a 16-bit signed integer can hold numbers from 2^15 (32768) to +2^15 1 (32767).

Question - 104 : - How many levels deep can include files be nested?

Answer - 104 : - Even though there is no limit to the number of levels of nested include files you can have, your compiler might run out of stack space while trying to include an inordinately high number of files. This number varies according to your hardware configuration and possibly your compiler.

Question - 105 : - What is the difference between declaring a variable and defining a variable?

Answer - 105 : - Declaring a variable means describing its type to the compiler but not allocating any space for it. Defining a variable means declaring it and also allocating space to hold the variable. You can also initialize a variable at the time it is defined.

Question - 106 : - How can I make sure that my program is the only one accessing a file?

Answer - 106 : - By using the sopen() function you can open a file in shared mode and explicitly deny reading and writing permissions to any other program but yours. This task is accomplished by using the SH_DENYWR shared flag to denote that your program is going to deny any writing or reading attempts by other programs. For example, the following snippet of code shows a file being opened in shared mode, denying access to all other files: /* Note that the sopen() function is not ANSI compliant... */ fileHandle = sopen(“C:DATASETUP.DAT”, O_RDWR, SH_DENYWR); By issuing this statement, all other programs are denied access to the SETUP.DAT file. If another program were to try to open SETUP.DAT for reading or writing, it would receive an EACCES error code, denoting that access is denied to the file.

Question - 107 : - How can I sort a linked list?

Answer - 107 : - Both the merge sort and the radix sort are good sorting algorithms to use for linked lists.

Question - 108 : - What does it mean when a pointer is used in an if statement?

Answer - 108 : - Any time a pointer is used as a condition, it means “Is this a non-null pointer?” A pointer can be used in an if, while, for, or do/while statement, or in a conditional expression.

Question - 109 : - Array is an lvalue or not?

Answer - 109 : - An lvalue was defined as an expression to which a value can be assigned. Is an array an expression to which we can assign a value? The answer to this question is no, because an array is composed of several separate array elements that cannot be treated as a whole for assignment purposes. The following statement is therefore illegal: int x[5], y[5]; x = y; Additionally, you might want to copy the whole array all at once. You can do so using a library function such as the memcpy() function, which is shown here: memcpy(x, y, sizeof(y)); It should be noted here that unlike arrays, structures can be treated as lvalues. Thus, you can assign one structure variable to another structure variable of the same type, such as this: typedef struct t_name { char last_name[25]; char first_name[15]; char middle_init[2]; } NAME; ... NAME my_name, your_name; ... your_name = my_name;

Question - 110 : - What is an lvalue?

Answer - 110 : - An lvalue is an expression to which a value can be assigned. The lvalue expression is located on the left side of an assignment statement, whereas an rvalue is located on the right side of an assignment statement. Each assignment statement must have an lvalue and an rvalue. The lvalue expression must reference a storable variable in memory. It cannot be a constant.


NCERT Solutions

 

Share your email for latest updates

Name:
Email:

Our partners