Join Our Email Alerts-Subscribe
Important Note:Login & Check Your Email Inbox and Activate Confirmation Link


Enter Your Email :

Copyright Disclaimer:
Section 107 of the Copyright Act Fair Use Contents .
We are forwarding content link(s) from our website to content website & We are not serving any contents.
Main Source:Google.com.All the Content PDF link(s) is/are obtained from GoogleSearch
for the purpose of Education & Teaching Intention. Not for commercial purpose.
Technicalsymposium.com is not liable/responsible for any copyright issues.


C Materials Free Download



45) Point out the error in the program given below, if any ?

main()

{

int a=10,b;

a>= 5 ? b=100 : b=200;

printf("\n%d",b);

}

A value is required in function main(). The second assignment should be written in parenthesis as follows:

a>= 5 ? b=100 : (b=200);

46) Point out the error in the following program

main()

{

const int x;

x = 128;

printf("%d",x);

}

Variable x should have been initialized during declaration. 

47) In C, what is the difference between a static variable and global variable?

A static variable ia declared outside of any function and it is accessible only to all the functions defined in the same file (as the static variable). In case of global variable, it can be accessed by any function (including the ones from different files). 

48) Write a c program to print Hello world without using any semicolon.

void main()

{

if(printf("Hello world"))

{

}

}

Same way, while and switch statements can be used to achieve this.

49) Write a C program to swap two variables without using third variable ?

#include stdio.h

int main()

{

int a=5,b=10;

a=b+a;

b=a-b;

a=a-b;

printf("a= %d b= %d",a,b);

}

50) What is dangling pointer in c?

If any pointer is pointing at the memory location/address of any variable, but if the variable is deleted or does not exist in the current scope of code, while pointer is still pointing to that memory location, then the pointer is called dangling pointer. For example, 

#include stdio.h

int *func();

int main()

{

int *ptr;

ptr=func();

printf("%d",*ptr);

return 0;

}

int * func()

{

int x=18;

return &x;

}

Output is Garbage value, since the variable x has been freed as soon as the function func() returned

51) What is wild pointer in c?

A pointer is known as wild pointer c, if it has not been initialized. For Example:

int main()

{

int *ptr;

printf("%u\n",ptr);

printf("%d",*ptr);

return 0;

}

Output: Any address, Garbage value.

Here ptr is wild pointer, because it has not been initialized. Wild pointer is not the same as NULL pointer. Because, NULL pointer doesn't point to any location, but a wild pointer points to a specific memory location but the memory may not be available for current application, which is very fatal. 

52) What is the meaning of prototype of a function?

Declaration of function is known as prototype of a function. Prototype says the name, parameter list and return type of a function but not the definition, this is same as declaring some variable but not defining it. For example, 

int printf(const char *, int/);

53) Write a c program to find size of structure without using sizeof operator?

struct XXX

{

int x;

float y;

char z;

};

int main()

{

struct XXX *ptr=(struct XXX *)0;

ptr++;

printf("Size of structure is: %d",*ptr);

return 0;



54) What is size of void pointer?

Size of all pointers are same in C, regardless of their type because pointers variable holds a memory location. And for a given system, this size is constant. The type of pointer is used to know the size of the data that the pointer is pointer is pointing to. 

55) What will be output of following program?

int main()

{

int a = 260;

char *ptr;

ptr =( char *)&a;

printf("%d ",*ptr);

return 0;

}

(A) 2 (B) 260 (C) 4 (D) Compilation error (E) None of above

Answer is B. 260 will take two byte memory space to reside and the bytes will be 1 and 4. Binary value of 260 is 00000001 00000100 (In 16 bit). So, ptr is only pointing to first 8 bit whose decimal value is 4. 

56) What will be the output?

#include "stdio.h"

int main()

{

char arr[100];

printf("%d", scanf("%s", arr));

/* Say the input is “hello” */

return 1;

}

The scanf returns the number of inputs it has successfully read, so the output will be 1.

57) Guess the output.

int main()

{

printf(6 + “Hello World”);

return 0;

}

The printf is a library function which takes a char pointer as input. Here the pointer in incremented by 6, so the pointer will advance from pointing 'H' to 'W'. So the output will be “World”. 

59) Guess the output?

int main()

{

printf("%c ", 6[“Hello World”]);

return 0;

}

In C, X[5] and 5[X] are the same. Here, 6[“Hello World”] will return the 6th element of the array “Hello World”, that is 'W'. 

What are main characteristics of C language?

C is a procedural language. The main features of C language include low-level access to memory, simple set of keywords, and clean style. These features make it suitable for system programming like operating system or compiler development. 

What is difference between i++ and ++i?

1) The expression ‘i++’ returns the old value and then increments i. The expression ++i increments the value and returns new value. 

2) Precedence of postfix ++ is higher than that of prefix ++.

3) Associativity of postfix ++ is left to right and associativity of prefix ++ is right to left.

4) In C++, ++i can be used as l-value, but i++ cannot be. In C, they both cannot be used as l-value.

What is l-value?

l-value or location value refers to an expression that can be used on left side of assignment operator. For example in expression “a = 3”, a is l-value and 3 is r-value. 

l-values are of two types:

“nonmodifiable l-value” represent a l-value that can not be modified. const variables are “nonmodifiable l-value”.

“modifiable l-value” represent a l-value that can be modified.

What is a pointer on pointer? 

It’s a pointer variable which can hold the address of another pointer variable. It de-refers twice to point to the data held by the designated pointer variable. 

Eg: int x = 5, *p=&x, **q=&p;

Therefore ‘x’ can be accessed by **q.

Distinguish between malloc() & calloc() memory allocation. 

Both allocates memory from heap area/dynamic memory. By default calloc fills the allocated memory with 0’s.

What is keyword auto for? 

By default every local variable of the function is automatic (auto). In the below function both the variables ‘i’ and ‘j’ are automatic variables. 

void f() {

int i;

auto int j;

}

NOTE - A global variable can’t be an automatic variable.

What are the valid places for the keyword break to appear. 

Break can appear only with in the looping control and switch statement. The purpose of the break is to bring the control out from the said blocks. 

Explain the syntax for for loop. 

for(expression-1;expression-2;expression-3) {

//set of statements

}

Source: Contents are provided by Technicalsymposium Google Group Members. 
Disclaimer: All the above contents are provided by technicalsymposium.com Google Group members. 
Further, this content is not intended to be used for commercial purpose. Technicalsymposium.com is not liable/responsible for any copyright issues.

Copyright Disclaimer:Section 107 of the Copyright Act Fair Use Contents .
We are forwarding content link(s) from our website to content website & We are not serving any contents. Main Source:Google.com.All the Content PDF link(s) is/are obtained from GoogleSearch for the purpose of Education & Teaching Intention. Not for commercial purpose. Technicalsymposium.com is not liable/responsible for any copyright issues.


Technical Interview Materials with Answers