C Interview Questions and Answers for Freshers

    1 Votes

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;
}
Page 6 of 8

Popular Videos

How to speak to people

How to speak so that people want to listen.

Got a tip or Question?
Let us know

Related Articles

C++ Interview Questions and Answers for Freshers, Experienced
Advanced C Interview Questions and Answers for Experienced
Embedded C Interview Questions and Answers