Technical Interview Question/Programs On C & C++

Que. a=5, b=3, c=a,b
         d=(a,b)
         Printf(c,d)
Ans: c=5, d=3

Ques. int *f1()
      {
int n;
return(n)
}
int *f2()
{
int *p;
*p=3;
return p;
}
int *f3()
{
int *p;
p=malloc();
return p;
}
Ans: No Error

Que: *p+=1
     *p++
     are these two same?
Ans: Not Same

Que: func(int i)
{
static int count;
count = count+i;
}
Ans: 1+2+3..
     (Count values does not go after function call)

Que: int num[3];
     num[3]=2;
Ans: First statement deals with SIZE
     Second statement deals with ELEMENT

Que: j=4;
     for(int i=0;i<5 i="" p="">     {
      j++;
      ++j;
      }
      Output of j=?
Ans: 14

Que: Brace "{" used in C for what?
Ans: CONVENTION

Que: Parameter in C passed by?
Ans: VALUE

Que: When An array is passed it is by?
Ans: Pointer

Que: Scanf can read?
Ans: any data type

Que: which can't be passed to subroutine?
Ans: Preprocessor Directive

Que: To get string of words.
Ans: gets()

Ques: External variable can be accesed?
Ans: in functions which use them

Que: What is the fuction clock() in C used for?
Ans: To calculate the actual processing times of a program, The value returned by clock should be compared to a value returned by a initial call to clock.

Que: fp=fopen(file.c,"r");
     what is the correct declaration for fp?
Ans: FILE *fp;

Que: main()
     {
static i=3;
printf("%d",i--);
return i>0?main():0;
      }
Ans: 321

Que: #define AREA(x) (3.14*x*x)
main()
{
float r1=6.25, r2=2.5, a;
a=AREA(r1);
printf("\n Area of the circle is %f",a);
a=AREA(r2);
printf("\n Area of the circle is%f",a);
}
Ans: Area of the circle is 122.656250
     Area of the circle is 19.625000

Que: intf()
void main()
{
f(1);
f(1,2);
f(1,2,3);
}
f(int i,int j,int k)
{
printf("%d%d%d",i,j,k);
}
What are the number of syntax error in the above?
Ans: NONE

Que: void main()
{
int i=7;
printf("%d",i++*i++);
}
Ans: 56

Que: #define one o
#ifdef one
printf("One is defined");
#ifndef one
printf("One is not defined");
Ans: One is defined

Que: void main()
{
int count=10, *temp, sum=0;
temp=&count;
*temp=20;
temp=∑
*temp=count;
printf("%d%d%d",count,*temp,sum);
}
Ans: 20 20 20

Que: what is alloca()?
Ans: It allocate & frees memory after use/after getting out of scope.

Que: main()
{
int x=5;
printf("%d%d%d/n",x,x<<2 x="">>2);
}
Ans: 5 20 1

Que: main()
{
char *p1="Name";
char *p2;
p2=(char*)malloc(20);
while(*p2++ = *p1++);
printf("%s\n",p2);
}
Ans: An empty string

Que: SBI of an object?
Ans: State [s] = Describe attribute value
     Behaviour [B] = Describe method
     Identity [I] = Object id for reference

Que: What is Garbage Collection?
Ans: Garbage collection is a process of releasing the memory used by the objects, which are no longer referenced. First we allocate a block of memory in the managed memory by using the new keyword.

Que: First OOP language?
Ans: SIMULA.

Que: What is virtual function?
Ans: Virtual function is a member of class & it's functionality can be overridden in it's derived class.

Que: What is interface?
Ans: Collection of abstract method.

Que: What is tokens?
Ans: Recognized by a compiler & it cannot be broken down into component element.

Que: What is sealed modifier?
Ans: Sealed modifier are the access modifiers where it can not be inherited by the method.

Que: This pointer?
Ans: Current Object of an class.

Que: Bank Account constructor : pulic int Bank Account()
{
balance=0;
}
find error?
Ans: Return type

Que: Write program swapping two numbers in C
Ans: # include
int main()
{ int x,y,temp;
printf("Enter the value of x&y\n");
scanf("%d%d",&x,&y);
printf("Before swapping \n x=%d\n y=%d \n",x,y);
temp=x;
x=y;
y=temp;
printf("After swapping x=%d y=%d",x,y);
return 0;
}

Que: Write program swapping two number using pointer
Ans: # include
int main()
{ int x,y,*a,*b,temp;
printf("Enter the value x&y");
scanf("%d%d",&x,&y);
printf("Before swapping x=%d y=%d",x,y);
a=&x;
b=&y;
temp=*b;
*b=*a;
*a=temp;
printf("After swapping x=%d y=%d",x,y);
return 0;
}

Que: Write program swapping two number
Ans: # include
main()
{ int a,b,c;
clrscr();
printf("Enter the value of a,b");
scanf("%d%d",&a,&b);
c=a;
a=b;
b=c;
printf("%d %d",a,b);
getch();
}

Que: Write program to interchange the values of two variables without using third variable.
Ans: # include
main()
{ int a,b; clrscr();
printf("enter the value a,b");
scanf("%d%d",&a,&b);
a=a+b;
b=a-b;
a=a-b;
printf("%d %d",a,b);
getch();
}

Que: Write a program to print the fibonnaci series.
Ans: # inlude
main()
{ long int c,i,n,a=0,b=1; clrscr();
printf("How many numbers of the series do you want");
scanf("%ld",&n);
printf("%6ld\n%6ld\n",a,b);
for(i=3;i { c=a+b;
a=b;
b=c;
if(c<=n)
printf("%6ld\n",c);
else break;
}
getch();
}

Que: write a program to print the factorial of a given number
Ans: # include
# include
void main()
{
int n=0,f=1,i=0; clrscr();
printf("Enter the number for finding factorial\n");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
f=f*i;
}
printf("The factorial is:%d",f);
getch();
}

Comments

Popular posts from this blog

Angular 4 + Cordova Boilerplate ::: Hybrid Mobile Application

In MVC 4 Save and Retrieve cookies