• +91 9971497814
  • info@interviewmaterial.com

Computer Interview Questions Answers

C Interview Questions Answers

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

Answer - 11 : - 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 - 12 : - What is indirection?

Answer - 12 : - If you declare a variable, its name is a direct reference to its value. If you have a pointer to a variable, or any other object in memory, you have an indirect reference to its value.

Question - 13 : - What are the characteristics of arrays in C?

Answer - 13 : - 1) An array holds elements that have the same data type 2) Array elements are stored in subsequent memory locations 3) Two-dimensional array elements are stored row by row in subsequent memory locations. 4) Array name represents the address of the starting element 5) Array size should be mentioned in the declaration. Array size must be a constant expression and not a variable.

Question - 14 : - What does static variable mean?

Answer - 14 : - there are 3 main uses for the static. 1. If you declare within a function: It retains the value between function calls 2.If it is declared for a function name: By default function is extern..so it will be visible from other files if the function declaration is as static..it is invisible for the outer files 3. Static for global variables: By default we can use the global variables from outside files If it is static global..that variable is limited to with in the file

Question - 15 : - Can the sizeof operator be used to tell the size of an array passed to a function?

Answer - 15 : - No. There’s no way to tell, at runtime, how many elements are in an array parameter just by looking at the array parameter itself. Remember, passing an array to a function is exactly the same as passing a pointer to the first element.

Question - 16 : - What are the differences between malloc() and calloc()?

Answer - 16 : - There are 2 differences. First, is in the number of arguments. malloc() takes a single argument(memory required in bytes), while calloc() needs 2 arguments(number of variables to allocate memory, size in bytes of a single variable). Secondly, malloc() does not initialize the memory allocated, while calloc() initializes the allocated memory to ZERO.

Question - 17 : - Why should we assign NULL to the elements (pointer) after freeing them?

Answer - 17 : - This is paranoia based on long experience. After a pointer has been freed, you can no longer use the pointed-to data. The pointer is said to dangle; it doesn’t point at anything useful. If you NULL out or zero out a pointer immediately after freeing it, your program can no longer get in trouble by using that pointer. True, you might go indirect on the null pointer instead, but that’s something your debugger might be able to help you with immediately. Also, there still might be copies of the pointer that refer to the memory that has been deallocated; that’s the nature of C. Zeroing out pointers after freeing them won’t solve all problems;

Question - 18 : - what is the diff between "new" and "operator new" ?

Answer - 18 : - "operator new" works like malloc.

Question - 19 : - Differentiate between a linker and linkage?

Answer - 19 : - A linker converts an object code into an executable code by linking together the necessary build in functions. The form and place of declaration where the variable is declared in a program determine the linkage of variable.

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

Answer - 20 : - 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.

Computer Contributors

krishan
Rajeev Katiyar
Yes Baroda

Share your email for latest updates

Name:
Email:

Our partners