Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Variables Pointer Array And Files - C Programming Questions For Job Interview

1. How will you change the value of a constant variable in C?
Answer: Constant can be changed by using the Pointer. Initialize a pointer to point to the value of a and then change the value using the pointer. 
#include<stdio.h>
int main()
{
const int = 5;
printf("%d", a);
int *k = (int *) &a;
*k = 10;
printf("%d", *k);
printf("%d", a);
return 0;
}

2. What is the output of the following program?
#define SQR(x) (x*x)
main()
{
int a, b = 3;
a = SQR(b + 2);
printf("%d", a);
}

a) 25
b) 11
c) Error
d) Garbage Value

Answer: b) 11.
Since it passes like (3+2) to #define, where it calculates as (3+2 * 3+2), as 1st preference is multiply & then addition, it evaluates as (3+ 2 * 3 +2) = (3+6+2)=11.


3. What is the output of the following code?
main()
{
if ((1 || 0) && (0 || 1)) {
printf("OK I am done.");
} else {
printf("OK I am gone.");
}
}
a) none of the above
b) compile error
c) OK I am gone
d) OK I am done

Answer: d)
((1 || 0) && (0 || 1)) will be:
(( 1 ) && ( 1 ))
(1 && 1) =>1: so will print: OK I am done.



Answer :1. Union allocates the Memory equal to the maximum memory required by the member of the union but structure allocates the memory equal to the total memory required by the members.
2. In union, one block is used by all the member of the union but in case of structure, each member has its own memory space.
3. Union is best in the environment where memory is less as it shares the memory allocated. But structure cannot be implemented in shared memory.
4. As memory is shared, ambiguity is more in union, but less in structure.
5. Self-referential union cannot be implemented in any data structure, but self-referential structure can be implemented.

5. What is a wild pointer?
Answer:Wild pointer is a pointer that doesn't point to either a valid object (of the indicated type, if applicable), or to a distinguished null value, if applicable.

C Programming Basic Questions
Array in Embedded C
C Programming Viva Questions
Dangling and Wild Pointers
Variables and Pointers Volatile Or Constant
C Questions for Job Interview
CONTINUE READING »


This post first appeared on IngenuityDias, please read the originial post: here

Share the post

Variables Pointer Array And Files - C Programming Questions For Job Interview

×

Subscribe to Ingenuitydias

Get updates delivered right to your inbox!

Thank you for your subscription

×