Select Category 
c interview questions answers c interview question answer. c interview questions answers c interview question answer. c interview questions answers c interview question answer. c interview questions answers c interview question answer. c interview questions answers c interview question answer.
What does it mean when a pointer is used in an if statement?
c interview questions answers c interview question answer. c interview questions answers c interview question answer. c interview questions answers c interview question answer. c interview questions answers c interview question answer. c interview questions answers c interview question answer.
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.
c interview questions answers c interview question answer. c interview questions answers c interview question answer. c interview questions answers c interview question answer. c interview questions answers c interview question answer. c interview questions answers c interview question answer.
c interview questions answers c interview question answer.  c interview questions answers c interview question answer.  c interview questions answers c interview question answer.  c interview questions answers c interview question answer.  c interview questions answers c interview question answer.  c interview questions answers c interview question answer.&nb
 

C Interview Questions Answers

C Interview Question - 16 : -

What does it mean when a pointer is used in an if statement?

C Interview Answer - 16 : -

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.
 

C Interview Question - 17 : -

Array is an lvalue or not?

C Interview Answer - 17 : -

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;
 

C Interview Question - 18 : -

What is storage class and what are storage variable ?

C Interview Answer - 18 : -

A storage class is an attribute that changes the behavior of a variable. It controls the lifetime, scope and linkage.
There are five types of storage classes
1) auto
2) static
3) extern
4) register
5) typedef
 

C Interview Question - 19 : -

what is meant by the ``equivalence of pointers and arrays'' in C?

C Interview Answer - 19 : -

Much of the confusion surrounding arrays and pointers in C can be traced to a misunderstanding of this statement. Saying that arrays and pointers are ``equivalent'' means neither that they are identical nor even interchangeable. What it means is that array and pointer arithmetic is defined such that a pointer can be conveniently used to access an array or to simulate an array. In other words, as Wayne Throop has put it, it's ``pointer arithmetic and array indexing [that] are equivalent in C, pointers and arrays are different.'')

Specifically, the cornerstone of the equivalence is this key definition:

A reference to an object of type array-of-T which appears in an expression decays (with three exceptions) into a pointer to its first element; the type of the resultant pointer is pointer-to-T.

 

That is, whenever an array appears in an expression, the compiler implicitly generates a pointer to the array's first element, just as if the programmer had written &a[0]. (The exceptions are when the array is the operand of a sizeof or & operator, or is a string literal initializer for a character array. As a consequence of this definition, and in spite of the fact that the underlying arrays and pointers are quite different, the compiler doesn't apply the array subscripting operator [] that differently to arrays and pointers, after all.

Given an array a and pointer p, an expression of the form a[i] causes the array to decay into a pointer, following the rule above, and then to be subscripted just as would be a pointer variable in the expression p[i] .If you were to assign the array's address to the pointer:

	p = a;
then p[3] and a[3] would access the same element.
 

C Interview Question - 20 : -

What is a null pointer assignment error? What are bus errors, memory faults, and core dumps?

C Interview Answer - 20 : -

These are all serious errors, symptoms of a wild pointer or subscript.
Null pointer assignment is a message you might get when an MS-DOS program finishes executing. Some such programs can arrange for a small amount of memory to be available “where the NULL pointer points to (so to speak). If the program tries to write to that area, it will overwrite the data put there by the compiler.
When the program is done, code generated by the compiler examines that area. If that data has been changed, the compiler-generated code complains with null pointer assignment.
This message carries only enough information to get you worried. There’s no way to tell, just from a null pointer assignment message, what part of your program is responsible for the error. Some debuggers, and some compilers, can give you more help in finding the problem.

Bus error: core dumped and Memory fault: core dumped are messages you might see from a program running under UNIX. They’re more programmer friendly. Both mean that a pointer or an array subscript was wildly out of bounds. You can get these messages on a read or on a write. They aren’t restricted to null pointer problems.
The core dumped part of the message is telling you about a file, called core, that has just been written in your current directory. This is a dump of everything on the stack and in the heap at the time the program was running. With the help of a debugger, you can use the core dump to find where the bad pointer was used.
That might not tell you why the pointer was bad, but it’s a step in the right direction. If you don’t have write permission in the current directory, you won’t get a core file, or the core dumped message

 

C Interview Question - 21 : -

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

C Interview Answer - 21 : -

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.
 

C Interview Question - 22 : -

Are pointers integers?

C Interview Answer - 22 : -

No, pointers are not integers. A pointer is an address. It is merely a positive number and not an integer.
 

C Interview Question - 23 : -

Does there exist any other function which can be used to convert an integer or a float to a string?

C Interview Answer - 23 : -

Some implementations provide a nonstandard function called itoa(), which converts an integer to string.

#include

char *itoa(int value, char *string, int radix);

DESCRIPTION
The itoa() function constructs a string representation of an integer.

PARAMETERS
value:
Is the integer to be converted to string representation.

string:
Points to the buffer that is to hold resulting string.
The resulting string may be as long as seventeen bytes.

radix:
Is the base of the number; must be in the range 2 - 36.

A portable solution exists. One can use sprintf():

char s[SOME_CONST];
int i = 10;
float f = 10.20;

sprintf ( s, “%d %f\n”, i, f );

 

C Interview Question - 24 : -

How can you determine the size of an allocated portion of memory?

C Interview Answer - 24 : -

You can’t, really. free() can , but there’s no way for your program to know the trick free() uses. Even if you disassemble the library and discover the trick, there’s no guarantee the trick won’t change with the next release of the compiler.
 

C Interview Question - 25 : -

Which bit wise operator is suitable for putting on a particular bit in a number?

C Interview Answer - 25 : -

The bitwise OR operator. In the following code snippet, the bit number 24 is turned ON:
some_int = some_int | KBit24;
 

C Interview Question - 26 : -

what about this? Isn't this an array assignment?
	char a[] = "Hello, world!\n";

C Interview Answer - 26 : -

No, that's an initialization. You are allowed to initialize arrays when you define them.
 

C Interview Question - 27 : -

How many levels of pointers can you have?

C Interview Answer - 27 : -

The answer depends on what you mean by levels of pointers. If you mean How many levels of indirection can you have in a single declaration? the answer is At least 12.
int i = 0;
int *ip01 = & i;
int **ip02 = & ip01;
int ***ip03 = & ip02;
int ****ip04 = & ip03;
int *****ip05 = & ip04;
int ******ip06 = & ip05;
int *******ip07 = & ip06;
int ********ip08 = & ip07;
int *********ip09 = & ip08;
int **********ip10 = & ip09;
int ***********ip11 = & ip10;
int ************ip12 = & ip11;
************ip12 = 1; /* i = 1 */
The ANSI C standard says all compilers must handle at least 12 levels. Your compiler might support more.
 

C Interview Question - 28 : -

What will be printed as the result of the operation below:

#define swap(a,b) a=a+b;b=a-b;a=a-b;
void main()
{
int x=5, y=10;
swap (x,y);
printf(“%d %d\n”,x,y)
; swap2(x,y);
printf(“%d %d\n”,x,y)
; }

int swap2(int a, int b)
{
int temp;
temp=a;
b=a;
a=temp;
return 0;
}
as x

C Interview Answer - 28 : -

10, 5
 

C Interview Question - 29 : -

What are the characteristics of arrays in C?

C Interview Answer - 29 : -

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.
 

C Interview Question - 30 : -

What is a method?

C Interview Answer - 30 : -

Method is a way of doing something, especially a systematic way; implies an orderly logical arrangement (usually in steps).