C Pointers 2

C Pointers 2



Ques 1. what is the output for the below code?

#include <stdio.h>
#include <stdlib.h>
int (*fun)();
int disp()
{
printf("\n this is display function");
}

int main()
{
fun=disp;
fun;
return 0;
}

options:
A. runtime error
B. this is display funtion
C. compiler error
D. prints some garbage string.


Ques 2. what is the output for the below code?
#include <stdio.h>
#include <stdlib.h>
int (*fun)();
int disp()
{
printf("\n this is display function");
}

int main()
{
fun=disp;
fun();
return 0;
}

options:
A. runtime error
B. this is display funtion
C. compiler error
D. prints some garbage string.




Ques 3. what is the output for the below code?

#include <stdio.h>
#include <stdlib.h>
int (*fun)(int, int, char );
int math(int x, int y, char ch)
{
if(ch == '+')
return x+y;
}

int main()
{
int ans;
fun=math;
ans = fun(22,33,'+');
printf("\n ans= %d", ans);
return 0;
}



options:
A. 0 
B. runtime error
C. compiler error
D. 55


Ques 4. what is the output for the below code?
#include <stdio.h>
#include <stdlib.h>
int (*fun[4])(int, int, char );
int math(int x, int y, char ch)
{
if(ch == '+')
return x+y;
else
return 0;
}

int main()
{
int ans;
fun[0]=math;
ans = fun[0](22,33,'+');
printf("\n ans = %d", ans);
return 0;
}

options:
A. 55
B. compiler error
C. 0 
D. 155


Ques 5. what is the output for the below code?
#include <stdio.h>
#include <stdlib.h>
typedef int (*f)(int, int, char);
f funptr[3];

int math(int x, int y, char ch)
{
if(ch == '+')
return x+y;
else
return 0;
}

int main()
{
int ans;
funptr[0] = math;
ans = funptr[0](2,3,'+');
printf("\n ans = %d", ans);
return 0;
}

options:
A. 55
B. 5
C. 0
D. compiler error


Ques 6. what is the output for the below code?
#include <stdio.h>
#include <stdlib.h>
void fun()
{
printf("\n this is fun().");
}

void math(int (*fee)())
{
fee();
}

int main()
{
math(fun);
return 0;
}

options:
A. prints garbage string.
B. run time error
C. compiler error
D. this is fun().


Ques 7. what is the output for the below code?

#include <stdio.h>
#include <stdlib.h>
void fun()
{
printf("\n this is fun().");
}
void fun2();

int main()
{
fun2=fun;
fun2();
return 0;
}

options:
A. run time error
B. this is fun().
C. compiler error
D. garbage string.


Ques 8. what is the output for the below code?

#include <stdio.h>
#include <stdlib.h>
int main ()
{
int arr[2][4] ={{4,1,3,4},{5,8,9,11}};
printf("%d, %d", ++(*arr[0]), *arr[0]);
return 0;
}

options:
A. 4 4
B. 5 5
C. 3 3
D. compiler error


Ques 9. what is the output for the below code?
#include <stdio.h>
#include <stdlib.h>
int main ()
{
int arr[2][4] ={{4,1,3,4},{5,8,9,11}};
printf("%d, %d", *(arr+1)[0], *arr[0]);
return 0;
}

options:
A. compiler error
B. 4, 1
C. 1, 4
D. 5, 4


Ques 10. what is the output for the below code?
#include <stdio.h>
#include <stdlib.h>
int main ()
{
int arr[2][4] ={{4,1,3,4},{5,8,9,11}};
arr++;
printf("%d, %d", *(arr+1)[0], *arr[0]);
return 0;
}
options:
A. 4, 1
B. 2, 3
C. Compiler error
D. 5, 8


Ques 11. what is the output for the below code?
#include <stdio.h>
#include <stdlib.h>
int main ()
{
int arr[8] ={4,1,3,4,5,8,9,11};
int *p=arr;

printf("%d %d", *(p+1), *(arr+1));
return 0;
}

options:
A. 1 1
B. 4 4
C. 5 5
D. compiler error


Ques 12. what is the output for the below code?
#include <stdio.h>
#include <stdlib.h>
int main ()
{
int arr[2][4] ={4,1,3,4,5,8,9,11};
int *p=arr[1];

printf("%d %d", *(p+1), *(arr[0]+2));
return 0;
}

options:
A. 1, 3
B. 8, 3
C. compiler error
D. 5, 9


Ques 13. what is the output for the below code?
#include <stdio.h>
#include <stdlib.h>

int main ()
{
int arr[2][4] ={4,1,3,4,5,8,9,11};
int *p=arr[0];

printf("%d %d", *(p+1), *(p+6));
return 0;
}

options:
A. 4, 8
B. compiler error
C. 1, 9 
D. 0, 0


Ques 14. what is the output for the below code?
#include <stdio.h>
#include <stdlib.h>

int main ()
{
int arr[2][4] ={4,1,3,4,5,8,9,11};
int *p=arr[0];

printf("%d %d", ++*(p+1), ++*(p+6));
return 0;
}
options:
A. 2, 10
B. compiler error
C. 3, 11
D. 0 , 0


Ques 15. what is the output for the below code?

#include <stdio.h>
#include <stdlib.h>
int main ()
{
int arr[2][4] ={7,1,44,4,5,8,9,11};
int *p=arr[0];

printf("%d %d", *p, ++(*p));
return 0;
}
options:
A. 8 8
B. 7 7
C. 1 1
D. 7 1



Answers

1. C 2. B 3. D 4. A 5. B 6. D 7. C 8. B 9. D 10. C 11. A 12. B 13. C 14. D 15. A

C Datatypes Q & A

C Datatypes Q & A


Ques 1. What is the output of following program. Assume that the numbers are stored in 2's complement form.

#include<stdio.h> 
int main()
{
   int m = -2;
   int n = ~1;

   printf("0x%x 0x%x ", m, n);

   return 0;
}

options:
A. 0xfffffffe 0xfffffffe
B. compiler error
C. -2 -2
D. -2 -1


Ques 2. which is invalid in the following code declaration in C?

1. short int q;
2. signed long a
3. long e;
4. unsigned short r;

options:
A. 1 & 2 valid 
B. 3 valid
C. 4 valid
D. all valid



Ques 3. what is the output for the below code?

#include<stdio.h>
int main()
{
   float x = 15.0,z;
   z = 9/5 * x+32;
   printf("z=%0.2f",z);
   return 0;
}


options:
A. 47.00
B. 59.00
C. 32.00
D. 45.00



Ques 4. what is the output for the below code?

#include<stdio.h>
int main()
{
   char d = '2';
   char e = 022;
    printf("%d %d", d,e);
    return 0;
}

options:
A. 18 18
B. 22 22
C. Compile time error
D. run time error



Ques 5. In C, sizes of an integer and a pointer always same.

options:
A. True
B. False


Ques 6. what is the output for the below code?
int main()
{
    void *gptr, g;
    g = 0;
    gptr = &g;
    printf("%v", *gptr);
    getchar();
    return 0;
}

options:
A. 0
B. runtime error
C. 48
D. Compile time error



Ques 7. what is the output for the below code?

#include<stdio.h>
int main()
{
    char m=0;
    char ch = 125;
    ch = ch+10;
    printf("%d\n ", ch);
    return 0;
}

options:
A. -121 115
B. -121 -101 
C. 135 115
D. compile time error



Ques 8. what is the output ?

#include<stdio.h>
int main()
{
    int x = -1;
    printf(" %x %x\n", x, sizeof(long));
    return 0;
}

options:
A. ffffffff 4
B. -1 4
C. compiler error
D. None of the above


Ques 9. what is the output for the below code?

#include<stdio.h>
int main()
{
    float x = 0.1;

    if ( x == 0.1 )
        printf("IF");
    else if (x == 0.1f)
        printf("ELSE IF");
    else
        printf("ELSE");
}


options:
A. ELSE IF
B. ELSE
C. IF
D. error


Ques 10. what is the output for the below code?

#include<stdio.h>
int main()
{
    char t = 125;
    int i;

    for(i=0; i<5; i++)
      printf("%d ", t++);

    return 0;
}

options:
A. 125 126 127 128 129
B. 125 126 127 -128 -129
C. infinete loop
D. none of the above 



Ques 11. what is the output for the below code?

#include<stdio.h>
int main()
{
    char t = 0;
    for(t=0; t<135; t++)
      printf("\n%d", t);
    return 0;
}

options:
A. prints 0 to 135
B. infinite loop
C. error
D. runtime error


Ques 12.  Which data type is most suitable for storing a number 65000 in a 32-bit system?

options:
A. signed short
B. unsigned short
C. long
D. int



Ques 13: Which of the following is a User-defined data type?

options:
A. typedef int signedint32;
B. typedef enum {Jan, Feb, Mar, Apr, MAy} Months;
C. struct {char str[10], int age};
D. all of the mentioned


Ques 14: What is the size of an int data type?

Options:
A. 4 bytes
B. 8 bytes
C. Depends on the system /compiler
D. 2 bytes

Ques 15:  What is the output for the below program?
#include<stdio.h>
    int main()
    {
        char ch;
        int j = 0;
        FILE *file;
        file = fopen("test.txt", "w+");
        fprintf(file, "%c", 'd');
        fprintf(file, "%c", -1);
        fprintf(file, "%c", 'g');
        fclose(file);
        file = fopen("test.txt", "r");
        while ((ch = fgetc(file)) !=  -1)
            printf("%c", ch);
        return 0;
    }

options:

A. d
B. depends on what fgets returns
C. depends on compiler 
D. infinite loop


Ques 16: What is the output for the below program?
#include<stdio.h>
int main()
{
    void *gptr;
    int *g;
    gptr=(int *)malloc(4);
    g=(int* ) gptr;
    *g=43;
    *(int *)gptr=34;
    printf("%d %d", *g, *(int*)gptr);

    getchar();
    return 0;
}

options:
A. 34 34
B. 35 35
C. compiler error
D. run time error


Ques 17: What is the output for the below program?
#include<stdio.h>
int main()
{
     int x,y;
    double d;

    x=44, y=5;
    d=x/y;
    printf("%lf", d);

    return 0;
}

options:
A. 8.80000
B. 8.0000
C. compiler error
D. run time error


Ques 18: What is the output for the below program?
#include<stdio.h>

int main()
{
    float x,y;
    double d;

    x=4.0, y=5.0;
    d=x/y/x;
    printf("%lf", d);

    return 0;
}

options:
A. 0.8000
B. 3.2000
C. 0.2000
D. run time error


Ques 19: What is the output for the below program?
#include<stdio.h>

int main()
{
    unsigned int m=121;
    signed int i=225;
    char c=34;

    c=i+m;    
    printf("%d",c);
    return 0;
}
options:
A. runtime error
B. compiler error
C. 346
D. 90

Ques 19: What is the output for the below program?
#include<stdio.h>
int main()
{
    unsigned int m = 65632;
    signed short i=225;
    i = m;
    printf("%i",i);
    return 0;
}

options:
A. 65632
B. 65631 
C. 96
D. 97

Answers

1. A 2. D 3. A 4. A 5. B 6. D 7. A 8. A 9. A 10. B 11. B 12. B 13. D 14. C 15. A 16. A 17. B 18. C 19. D 20. C

Interview QA 2

Interview QA 2



Ques 1. what is the output for the below code?

#include <stdio.h>
#include <stdlib.h>
#define DEBUG(x, %d) printf("DEBUG : %d", x) 
int main()
{
    int x=44;
    DEBUG(x,%d);
    return 0;
}

Explanation:
Here in DEBUG macro %d is not a variable, it gives compiler error.

Rules for naming identifiers
A valid identifier can have letters (both uppercase and lowercase letters), digits and underscores.
The first letter of an identifier should be either a letter or an underscore.
You cannot use keywords as identifiers.
There is no rule on how long an identifier can be. 
However, you may run into problems in some compilers if the identifier is longer than 31 characters.



Ques 2. what is the ouput?
#include <stdio.h>
#include <stdlib.h>
#define cube(x) x*x*x
int main()
{
    int x=2, y=4;
     y=y/cube(x) ;
     printf("%d",y);
    return 0;
}

Explanation:
after preprocessing  the statement  y=y/cube(x)
become   y=y/x*x*x;
         it evaluates as
         y= (y/x)*x*x = (4/2)*2*2= 2*2*2= 8



Ques 3. what is dirty bit?

Explanation:
 In computer dirty bit or modified bit indicates the block of memory is modified or not .
if the dirty bit is set then the block of memory is modified otherwise id not modified.
the operating system checks this bit before writing the block of memory to secondary storage
if the bit is set then the block of memory is written to secondary storage.


Ques 4. what is the output for the below code?
#include <stdio.h>
#include <stdlib.h>
int main()
{
    int x=-2;
    printf("%x",x>>3);
    return 0;
}

Explanation:
-2 = fffffffe = 11111111 11111111 11111111 11111110
after  >> 3
 = ffffffff

if define the x as unsigned int
after right shift it becomes 1fffffff



Ques 5. which is efficient in switch or if else ?

Explanation:
    In if else each the condition has to be evaluated at run time,
in switch only evaluating the variable value is done at run time, 
remaining cases is fixed and it is evaluated at compile time.


Ques 6. what is the output for the below code?

#include <stdio.h>
#include <stdlib.h>
int main()
{
    int ch =1, y=0;

    if(ch==1, y>ch )
    {
     printf("\n if is evaluated.");
    }
    else
    {
        printf("\n else is evaluated.");
    }

    return 0;
}

Explanation:
Here the if condition is correct in syntax,
however it will evaluate the the first condition, and it considers 
the last condition for control flow.


Ques 7. what is the output for the below code?
#include <stdio.h>
#include <stdlib.h>
int main()
{
    int ch =1, y=0;

     printf("\n %d", scanf("%d %d", &ch, &ch));


    return 0;
}

Explanation:
Here the scanf funtion returns how many arguments it is reading.
The return value of scanf funtion is printed in printf funtion.


Ques 8. what are near, huge, far memory ?

Explanation:
near means the variable is stored in the current segment of 64 kb of memory
far means the variable is stored or can access within in the 128kb of memory,
here the segment register is fixed
huge means the variable is stored or can access more than 128kb of memory, 
here the segment register can change.


Ques 9. write a program for swap the bytes in the variable var1=0x4567 ?

#include <stdio.h>
#include <stdlib.h>
int main()
{
    int var1 =0x3255;
    var1 = (var1 >> 8) | ((var1&0xff)<<8);
    printf("0x%x",var1);
    return 0;
}




Ques 10. difference between <> and "" in #include statement?

Explanation:
< > means the file is included from the library or predesignated by the compiler.
the compiler will search the included file in that directory. 
Normally this is used to include the standard header files.

" " means the the compiler searches the included header file in the current working directory.
normally it used to include the user defined header files.

Storage Classifiers

Storage Classifiers



Ques 1. what are stoagre classifiers in c?


options:
A. auto, static, register, extern 
B. auto, float, register, extern
C. char, static, register, extern
D. auto, static, register, int


Ques 2. what is the output for the below code?
#include <stdio.h>
#include <stdlib.h>
void fun();
int main()
{
fun();
}

void fun()
{
    static int x=4;
  if(x-- != 0 )
  {
    fun();
    printf("%d ",x);
  }
}

options:
A.  0 0 0 0
B. -1 -1 -1 -1 
C.  4 3 2 1
D.  infinite loop


Ques 3. what is the output for the below code?
#include <stdio.h>
#include <stdlib.h>
void fun();
int main()
{
fun();
}

void fun()
{
    static int x=4;
  if(x-- != 0 )
  {
    printf("%d ",x);
    fun();
  }
}

options:
A.  0 0 0 0
B. -1 -1 -1 -1 
C.  3 2 1 0
D.  infinite loo


Ques 4. what is the output for the below code?
#include <stdio.h>
#include <stdlib.h>
int main()
{
    auto int abc = 34;
    auto int * const ptr = &abc;
    *++ptr;
    printf("%d", abc);

    return 0;
}

options:
A. 34
B. 35
C. compiler error
D. run time error


Ques 5. what is the output for the below code?
#include <stdio.h>
#include <stdlib.h>
int main()
{
    auto int abc = 34;
    auto int * const ptr = &abc;
    ++*ptr;
    ++*ptr;
    --*ptr;
    printf("%d", abc);

    return 0;
}

options:
A. 34
B. 37
C. 36
D. 35


Ques 6. what is the output for the below code?
#include <stdio.h>
#include <stdlib.h>
int main()
{
    register int abc = 34;
    register int * const ptr = &abc;
    --*ptr;
    printf("%d", abc);

    return 0;
}

options:
A. 33
B. compiler error
C. 34
D. 35342


Ques 7. what is the output for the below code?
#include <stdio.h>
#include <stdlib.h>
int main()
{
    register int abc = 3;

    for(abc=3; ;)
    printf("%d", abc);

    return 0;
}

options:
A. infinite loop 
B. 3 3 3
C. compiler error
D. runtime error


Ques 8. what is the output for the below code?
int abc;
int main()
{
    int abc = 3;
    printf("%d\n ",abc);
    return 0;
}

options:
A. 0
B. 3
C. compiler error
D. runtime error


Ques 9. what is the output for the below code?
typedef static int abc ;

abc si=3;
int main()
{
    si++;
    printf("%d\n ",si);
    return 0;
}

options:
A. 4
B. runtime error
C. compiler error 
D. 3


Ques 10. what is the output for the below code?

typedef int abc ;

abc si=3;
int main()
{
    si++;
    si++;
    --si;
    printf("%d\n ",si);
    return 0;
}

options:
A. 6 
B. 5
C. 3
D. 4


Ques 11. what is the output for the below code?
int gi =332;
extern int gi ;

int main()
{
    printf("%d\n ",gi);
    return 0;
}

options:
A. 332
B. 0
C. compiler error
D. runtime error


Ques 12. what is the output for the below code?
volatile const int v =332;
int main()
{
    v += 4;
    printf("%d\n ",v);
    return 0;
}

options:
A. 336
B. compiler error
C. 332
D. runtime error


Ques 13. what is the output for the below code?
volatile int v =332;
int main()
{
    v += 4;
    printf("%d\n ",v);
    return 0;
}

options:
A. compiler error
B. 332
C. 336
D. runtime error


Ques 14. what is the output for the below code?
volatile int v =332;
int main()
{
    static int i=3;
    printf("%d ",v);

    {
     auto int p=89;
     i++;
     printf(" %d ", p);
    }
    {
        register int s=5;
        printf(" %d %d",s, i);
    }

    return 0;
}

options:
A. compiler error
B. run time error
C. 332 89 5 4
D. 332 89 5 3


Ques 15. what is the output for the below code?
volatile int v =32;
void fun();
int main()
{
    static int i=3;
    printf("%d ",v);

    {
     auto int p=89;
     i++;
     printf(" %d ", p);
    }
    {
        register int s=5;
        printf(" %d %d",s, i);
    }
fun();
    return 0;
}

void fun()
{
    v++;
 printf(" %d", v);
}

options:
A. 32 89 5 4 33
B. compiler error
C. run time error
D. 32 89 5 3 32


Answers

1. A 2. B 3. C 4. C 5. D 6. B 7. A 8. B 9. C 10. D 11. A 12. B 13. C 14. C 15. A

Dynamic Memory Allocation QA

Dynamic Memory Allocation QA



Ques 1. what is the output for the below code?

#include <stdio.h>
#include <stdlib.h>

int main()
{
    char *s;
    s=malloc(26);
    strcpy(s, "ptinstitute.in");
    printf("%s\n",s);
    return 0;
}

options:
A. ptinstitute.in
B. 0
C.compiler error
D. runtime error


Ques 2. what is the output for the below code?
#include <stdio.h>
#include <stdlib.h>
int main()
{
    char *s;
    s=malloc(26);
    strcpy(s, "good morning");
    free(s);
    printf("%s\n",s);
    return 0;
}
options:
A. good morning
B. garbage string
C. comipler error
D. rutime error


Ques 3. what is the output for the below code?
#include <stdio.h>
#include <stdlib.h>
int main()
{
    char *s;
    s=malloc(26);
    s=NULL;
    strcpy(s,"good");
    printf("%s\n",s);
    return 0;
}

options:
A. runtime error
B. good
C. 0
D. compiler error


Ques 4. what is the output for the below code?
#include <stdio.h>
#include <stdlib.h>
int main()
{
    char *s;
    s='g';
    printf("%s\n",s);
    return 0;
}

options:
A. compiler error
B. 0
C. g
D. run time error


Ques 5. what is the output for the below code?
#include <stdio.h>
#include <stdlib.h>
int *foo(void)
{
    int x=22;
    return &x;
}

int main()
{
    int *w;
    *w=foo() ;
    printf("\n %d", *w);
    return 0;
}


options:
A. 0
B. 22
C. run time error
D. garbage value


Ques 6. what is the output for the below code?
#include <stdio.h>
#include <stdlib.h>
int foo(int *s)
{
    int *x=s;
    return *x;
}

int main()
{
    int w[1]={23};
    w[0]=foo(w) ;
    printf("\n %d", *w);
    return 0;
}


options:
A. run time error
B. 23
C. 0
D. garbage value


Ques 7. what is the output for the below code?
#include <stdio.h>
#include <stdlib.h>
int* foo(int *s)
{
    int *x=s;
    x++;
    return x;
}

int main()
{
    int w[4]={56,3,44,5};
    int *p;
    p=foo(&w[0]) ;
    printf("\n %d", *p);
    return 0;
}

options:
A. 44
B. 56
C. 3
D. run time error


Ques 8. what is the output for the below code?
int * foo(int *s)
{
    s=(int *)malloc(4);
    return s;
}

int main()
{
    int *p;
     p= foo(p);
    *p=283;
    printf("\n %d", *p);
    return 0;
}

options:
A. 283
B. 284
C. run time error
D. compiler error 


Ques 9. what is the output for the below code?
int main()
{
    int *p;
     p= (int *)malloc(4);
    *p=283;
    ++*p;

    printf("\n %d", *p++);
    return 0;
}


options:
A. 281 
B. 283
C. 285
D. 284


Ques 10. what is the output for the below code?
int main()
{
    int  *q;

     q=calloc(12,1);
    *q=54;
    *(++q)=78;

    printf("\n %d %d", *(--q), *(q));
    return 0;
}

options:
A. run time error
B. 54 78
C. 55 79
D. 53 77


Ques 11. what is the output for the below code?
int main()
{
    int  *q[2];

     q[0]=calloc(4,2);
     q[1]=calloc(4,2);
    **q=54;
    *q[1]=58;
     ++(*q[1]);

    printf("\n %d %d",  **q, *q[1]);
    return 0;
}

options:
A. 55 58
B. 54 58
C. 54 59
D. run time error


Ques 12. what is the output for the below code?
int main()
{
    int  *q[2];

     q[0]=(int *)calloc(4,2);
     q[0]=(int *)realloc(q[0], 20);

    **q=54;
    ++**q;
    *(q[0]+3) = 78;
    --(*(q[0]+3));

    printf("\n %d %d",  **q, *(*q +3));
    return 0;
}


options:
A. 54 78
B. 55 77
C. 54 78
D. run time error


Ques 13. what is the output for the below code?
int main()
{
    int  ****p;
    int  ***q;
    int  **r;
    int  *s;

   s=(int *)malloc(4);
   r=&s;
   q=&r;
   p=&q;

   *s=47;

    printf("\n %d %d %d %d",  *s, **r, ***q, ****p);
    return 0;
}


options:
A. run time error
B. 47 46 47 0
C. 46 45 0 0
D. 47 47 47 47


Ques 14. what is the output for the below code?
int main()
{
    int  ****p;
    int  ***q;
    int  **r;
    int  *s;

   s=(int *)malloc(4);
   r=&s;
   q=&r;
   p=&q;

   *s=47;
   ++**r;
   ++***q;
   ++****p;

    printf("\n %d %d %d %d",  *s, **r, ***q, ****p);
    return 0;
}

options:
A.47 47 48 47 
B.50 50 50 50
C. 47 46 50 47
D. 47 48 49 59


Ques 15. what is the output for the below code?
int main()
{
    int  *s;
    s=(int *)calloc(4, 5);
    *s=45;
    s++;
    *s=56;
    *s=++(*s);

    printf("\n %d %d ",  *s, *(s-1));
    return 0;
}
options:
A. 45 57
B. 56 45
C. 57 45
D. 45 56


Ques 16. what is the output for the below code?
int main()
{
    int  *s;
    s=(int *)calloc(4, 2);
    s=realloc(s, sizeof(int)*4);
    *s=45;
    s++;
    *s=56;
    *s=++(*s);
    *(++s) =78;
    *(++s) =97;

    printf("\n %d %d %d %d",  *s, *(s-1), *(s-2), *(s-3));
    return 0;
}

options:
A. 57 97 45 57
B. 78 97 45 57
C. 97 78 57 45
D. 45 57 78 97


Ques 17. what is the output for the below code?
int main()
{
    int  *s[1];
    *s = (int *)malloc(4);
    *s = realloc(*s, sizeof(int)*3);
    **s = 45;
    ++(*s);
    **s=56;
    *(++(*s)) =78;
    *(++(*s)) =97;

    printf("\n %d %d %d %d",  **s, *(*s-1), *(*s-2), *(*s-3));
    return 0;
}
options:
A. 45 56 78 97 
B. 97 78 56 45
C. 45 56 97 78
D. 56 45 78 97


Answers

1. A 2. B 3. A 4. D 5. C 6. B 7. C 8. A 9. D 10. B 11. C 12. B 13. D 14. B 15. C 16. C 17. B

Advanced Pointers

Advanced Pointers



Ques 1. what is the output for the below code?

#include <stdio.h>
#include <stdlib.h>
int * add(int *p, int *q)
{
 int sum;
  sum=*p+*q;
  return ∑
}

int main()
{
  int r = 20, s=3;
  int *sum;
  int *p = &r, *q=&s;

  sum=add(p, q);

  printf("%d ", *sum);
  return 0;
}

options:
A. runtime error
B. 23
C. 0
D. compiler error



Ques 2. what is the output for the below code?

#include <stdio.h>
#include <stdlib.h>

int * add(int *p, int *q)
{
 int *sum =(int*)malloc(4);
  *sum=*p+*q;
  return sum;
}

int main()
{
  int r = 20, s=3;
  int *sum;
  int *p = &r, *q=&s;

  sum=add(p, q);

  printf("%d ", *sum);
  return 0;
}

options:
A. compiler error
B. runtime error
C. 23
D. 0


Ques 3. what is the output for the below code?
#include <stdio.h>
#include <stdlib.h>

void swap(int *p, int *q)
{
 int t;
 t=*p;
 *p=*q;
 *q=t;
}

int main()
{
  int r = 20, s=3;
  int *p = &r, *q=&s;

  swap(p, q);

  printf("*p=%d *q=%d", *p, *q);
  return 0;
}

options:
A. *p=20 *q=3
B. runtime error
C. *p=3 *q=20
D. compiler error


Ques 4. what is the output for the below code?
#include <stdio.h>
#include <stdlib.h>
void swap(int *p, int *q)
{
 int t;
 t=p;
 p=q;
 q=t;
}

int main()
{
  int r = 20, s=3;
  int *p = &r, *q=&s;

  swap(p, q);

  printf("*p=%d *q=%d", *p, *q);
  return 0;
}

options:
A. compiler error
B. *p=20 *q=3
C. *p=3 *q=20
D. run time error


Ques 5. what is the output for the below code?
#include <stdio.h>
#include <stdlib.h>
int main()
{
  int r = 20, s=3;
  int *p = r, *q = s;

  printf("*p=%d *q=%d", *p, *q);
  return 0;
}

options:
A. 3, 20
B. 20, 3
C. compiler error
D. runtime error


Ques 6. what is the output for the below code?
#include <stdio.h>
#include <stdlib.h>
int main()
{
   int (*q)[5];
   printf("%d",  sizeof(*q));
   return 0;
}

options:
A. compiler eror
B. 4
C. 20
D. runtime error


Ques 7. what is the output for the below code?
#include <stdio.h>
#include <stdlib.h>
int main()
{

   int (**q)[4] ={3,4,5,6,7,6};
   printf("%d",  sizeof(**q));
   return 0;
}

options:
A. 4
B. 16
C. 24
D. runtime error



Ques 8. what is the output for the below code?

#include <stdio.h>
#include <stdlib.h>
int main()
{
   int q[2][3][2] ={3,4,5,6,7,6};
   printf("%d",  sizeof(q));
   return 0;
}

options:
A. 20
B. 24
C. 4
D. 48


Ques 9. what is the output for the below code?

#include <stdio.h>
#include <stdlib.h>
int main()
{

   int q[6] ={3,4,5,6,7,6};
   int *r=(q+1);
   printf("%d %d",  *(r+2), *r++);
   return 0;
}

options:
A.
B.
C.
D.


Ques 10. what is the output for the below code?

#include <stdio.h>
#include <stdlib.h>
int main()
{

   int q[6] ={3,4,5,6,7,6};
   int *r=(q+1);

   printf("%d %d",  *(r+2), *r++);
   return 0;
}

options:
A. 7, 4
B. 6, 4
C. 5, 4
D. 5, 6


Ques 11. what is the output for the below code?

#include <stdio.h>
#include <stdlib.h>
int main()
{

   int p =32;
   int *q=&p;
   int **r=&q;

   printf("%d %d",  **r, *q);
   return 0;
}

options:
A. 32 32
B. 0 0
C. grabage value
D. runtime error



Ques 12. what is the output for the below code?

#include <stdio.h>
#include <stdlib.h>
int main()
{

   int p =32;
   int *q=&p;
   int **r=q;

   printf("%d %d",  **r, *q);
   return 0;
}

options:
A. 32 32
B. 0 0
C. grabage value
D. runtime error



Ques 13. what is the output for the below code?

#include <stdio.h>
#include <stdlib.h>
int main()
{

   char *p[] ={"welcome", "good", "test", "computer", "ptinstitute.in" };
   int **q[]={ p+1, p+2, p+3};
   int ***r=q;

   printf("%s %s",  **r, **(r+1));
   return 0;
}

options:
A. good test
B. welcome good
C. welcome test
D. test good


Ques 14. what is the output for the below code?

#include <stdio.h>
#include <stdlib.h>
int main()
{
   char *p[] ={"welcome", "good", "test", "computer", "ptinstitute.in" };
   int **q[]={ p+1, p+4, p+3};
   int ***r=q;
   r++;
   printf("%s %s",  **r, **(r+1));

   return 0;
}

options:
A. computer ptinstitute.in
B. ptinstitute.in computer
C. welcome good
D. runtime error



Ques 15. what is the output for the below code?

#include <stdio.h>
#include <stdlib.h>
int main()
{
   char *p[] ={"welcome", "good", "test", "computer", "ptinstitute.in" };
   int **q[]={ p+1, p+4, p+3};

   printf("%s %s",  ++(*p), *(p+2));

   return 0;
}

options:
A. good test
B. welcome test
C. elcome test
D. ood test


Ques 16. what is the output for the below code?

#include <stdio.h>
#include <stdlib.h>

int main()
{
   char *p[] ={"welcome", "good", "test", "computer", "ptinstitute.in" };
   int **q[]={ p+1, p+4, p+3};

   printf("%s %s",  **q, **(q+2));

   return 0;
}

options:
A. test computer
B. welcome test
C. welcome good
D. good computer


Ques 17. what is the output for the below code?
#include <stdio.h>
#include <stdlib.h>

int main()
{
   char *p[] ={"welcome", "good", "test", "computer", "ptinstitute.in" };
   int **q[]={ p+1, p+4, p+3};

   printf("%s %s",  *(*q++), **(q+2));

   return 0;
}
options:
A. compiler error
B. runtime error
C. welcome good
D. good test


Ques 18. what is the output for the below code?
#include <stdio.h>
#include <stdlib.h>

int main()
{
   char *p[] ={"welcome", "good", "test", "computer", "ptinstitute.in" };
   int **q[]={ p+1, p+4, p+3};

   printf("%s %s",  *(*q)++, **(q+2));

   return 0;
}
options:
A. compiler error
B. runtime error
C. welcome good
D. good computer


Ques 19. what is the output for the below code?
#include <stdio.h>
#include <stdlib.h>

int main()
{
   char *p[] ={"welcome", "good", "test", "computer", "ptinstitute.in" };
   int **q[]={ p+1, p+4, p+3};
p[1]= p[1] + 2;
p[3]= p[0] + 4;
   printf("%s %s",  *(*q)++, **(q+2));

   return 0;
}

options:
A. od mputer 
B. runtime error
C. welcome good
D. od ome



Ques 20. what is the output for the below code?
#include <stdio.h>
#include <stdlib.h>

void fun( char *p)
{
    printf("\n %s", ++p);

}
int main()
{
   char *p[] ={"welcome", "good", "test", "computer", "ptinstitute.in" };
   fun(p[2]);
   return 0;
}


options:
A. est 
B. runtime error
C. compiler error
D. test



Answers

1. A 2. C 3. C 4. B 5. D 6. C 7. B 8. D 9. C 10. A 11. A 12. D 13. A 14. B 15. C 16. D 17. A 18. D 19. D 20. A

Why C Is The Preferred Language For Embedded Systems

Why C Is The Preferred Language For Embedded Systems

Hello Friends,
I believe you wonder why C language is the preferred language for the embedded system, so here is the step by step analysis for you.

History Of C Programming

Before we enter into C language, let’s go through the history of computation. In around 1949 first computational electronic delay storage automatic calculator was incorporated with an assembler. So assembly language started gaining uses. Assembly language was based on mnemonics. In the year 1953 John W Backus and its team proposed a new language to its senior at IBM, and come up with one language that was based on assembly language but more user-friendly. This language was FORTON, the name derived from Formula Translation.

This language gain lot of popularity, used in many computational an intensive application like computational physics, numeric chemistry, weather prediction, crystallography, etc.

Now it was a time of 1969-70 when Dennis Ritchie and Ken Thompson we working in Bell labs. Ken was having a lot of ideas to improve paging, segmentation, process switch, etc. but to develop all those he was having the option to either improve the compiler of FORTON and make it strong or develop from the beginning. Both of then choose later option and started with some basic language available at that time.

Within 2 years of core working UNIX took a shape and the language C come into existence. The good part is C language is its compiler is written into a similar language like C, which is an amazing feature of C language.

Importance Of C in Embedded System

So now you can understand C language comes into existence with the motive to work develops operating system UNIX. C language is not a perfect language, it has many drawbacks like run-time checking, a lake of expectation handling, etc, but the perfect language is not yet created. Now C language is around 50 years old language, having a very very strong presence in the world of embedded systems, system programming, System programming. So for sure another next 50 years, C language will maintain its popularity and even increase. Now we start a discussion on why C language is the preferred language for embedded system development. As in this topic, we want to analyze why C has preferred the language in embedded systems, so we should know what embedded system is and what his limitation is. An embedded system is a normally small electronic device that is meant for a single purpose. As it is a small device then it is having the following limitation.

1) Low Memory Size

Normally microcontroller is coming in the smaller size, they are having a memory as low as 128 bytes. Inbuilt memory varies based on controller to controller. So the programming language should be such that which generates optimized code and occupied less memory footprint.
After C99 standard introduces, many optimization techniques and keywords are included in C language. The word “volatile” is directly dedicated to optimization.
Now a day new compiler is having the capability to generate so optimized code that even manually writing may not be possible.

2) Low Computational Power

Since the varying range of the controller, there is a possibility that for many small applications we may have less computational power. In C language has the capability to generate optimized code so that it consumes less power. Although the power required directly depends upon microcontroller internal architecture.

3) Uncontrolled And Infinite Life

Embedded application run for infinite time in the program, so code written into it should be thoroughly tested and validate so that it will work for life long. Thanks to the debugging environment available in C language, we can run the application in the acceleration mode and validate the application into debug mode to predict the lifelong behavior.

4) Mass Production Of Device

Since the embedded device is normally produced in term of million, so the language should support for automation and real-time support so that calibration, production testing, sales is possible easily. Even sometimes we also need to update firmware OTA – over the air.

So C language is supporting all possible ways in the embedded system.

What C Language Offer To Embedded System

Readability

C language syntax is easy to understand and it medium-level language. It is having the capability to interact with high-level languages like JAVA and C# and at the same time, C language is having the capability to interact with low-level Assembly language. Since C language is a procedure-oriented language, it helps to write modular code, which is highly readable. Embedded application code is written once then the main task is to maintain them throughout the product life, fix the bug, control version, testing, and validation. For all the above points we need to have code should be readable.

Portability

In the embedded system we need to write the code in one controller and release the product. Now suppose the controller used in obsolete and no more available for production. In this case, we need to move our source code to the new microcontroller, if the language is not supporting portability then we may need to start product development again. C language is highly capable to have portable code. Even more than 90% (on an average) code is capable to have portable and can be directly used into another controller, the available cross compiler takes care of many interoperable issues and as user prospect porting from one controller to other is not a very difficult task.

Simplicity

C language is easy to learn, it is having English like a keyword that is more relevant to the use case. Like keyword if, while, switch case, address, etc. all these keywords and similarly used in the English language also with almost similar use. Since C language is module language, once the student understands how to use the individual component then it will be very easy to use that module anywhere in programming. For example, once the student understands how to use, for loop in C language then it will be used as it is many places during programming.

Maintainability

There are many source control software and website are available that help to maintain source code, the main CVS, PVCS, Git-hub, etc. In the C language also there are many compile-time directives that help to maintain the source code version. The main compile-time keywords are #if, #else, #elif, #endif, #define etc. Using the above keyword, the user can do version control to make a good working code.

Scalable

C language is scalable to the extent that Linux is a million lines of code is written into C language. On average every day around 20-30 thousand lines of code are added into Linux OS itself. So C language is scalable up to the extent thought become limits.

Reliability

C language generates reliable code, its reliability making him use for Aerospace, avionics, defense, mission-critical application, nuclear plants, automobile products.

In the embedded system all most all the time we need to consider the following points during development.

1) Processor Independent

We should able to write code which will work on all processor.

2) Portability

The code should be easy to portable from one microcontroller to another.

3) Bit Manipulation

Usably in the embedded system, we are using bits and IO operation very frequently. Language should support this.

4) Memory Management

5) Code Optimization Possibility

6) Built-in Library Function

C is having many library functions available which can be used during application/system development.

Conclusion

Now being many years giving embedded systems training in Bangalore, At Professional Training Institute, We had come to ways across that C language is one of the most preferred languages in the embedded system. No language can replace C in the coming 20-30 years. It is having many bright career scope in the coming future. As many companies are coming for recruitment to us and asking for proficiency in C language only. Even during the embedded system training course, We focus mainly on C language gives the student to learn the C language up to 3 months. So let’s gear up and make your career into an embedded system, for that you must have an expert level of understanding in C level.

Best wishes for the coming future…

C Operator Q&A

C operators Q & A


Ques 1. what is the output for the below code?
#include <stdio.h>
#include <stdlib.h>

int main()
{
    int m,n,p;

    m=(1,2,3);
    p =1,2,3;

    printf("i = %d\n",m+p);
    return 0;
}

options:
A. 4
B. 2
C. 6
D. compile time error



Ques 2. what is the output for the below code?

#include <stdio.h>
#include <stdlib.h>

int main()
{
    int x=2,y=2,z=1,k=4, h=3;

    z+=x==y=k==h;

    printf("Hello world! %d\n",z);
    return 0;
}

options:
A. 2
B. compiler error lvalue required 
C. 3
D. 4


Ques 3. what is the output for the below code?
#include <stdio.h>
#include <stdlib.h>
int main()
{
    int x=2,y=2,z=1,k=4, h=3;

    z+=x==(y=k==h);

    printf("%d\n",z);
    return 0;
}

options:
A. 2
B. 0
C. 1
D. compiler error


Ques 4. what is the output for the below code?
#include <stdio.h>
#include <stdlib.h>
int main()
{
    int xyz=2,3,4;

    xyz+=5;
    printf("%d\n",xyz);
    return 0;
}

options:
A. 9
B. 8
C. 7
D. compiler error


Ques 5. what is the output for the below code?
#include <stdio.h>
#include <stdlib.h>
int main()
{
    int xyz=(2,3,4);

    xyz+=5;
    printf("%d\n",xyz);
    return 0;
}

options:
A. 7
B. 9
C. 8
D. compiler error


Ques 6. what is the output for the below code?
#include <stdio.h>
#include <stdlib.h>
int main()
{
    int mn=5;
    ++mn++;

    printf("%d\n",mn);
    return 0;
}

options:
A. 6
B. compiler error
C. 7
D. 8


Ques 7. what is the output for the below code?
#include <stdio.h>
#include <stdlib.h>
int main()
{
    int xyz;
    xyz=2,3,4;

    xyz+=5;
    printf("%d\n",xyz);
    return 0;
}

options:
A. 9
B. 8
C. 7
D. compiler error


Ques 8. what is the output for the below code?
#include <stdio.h>
#include <stdlib.h>
int main()
{
    int mn=5;
    ++mn;

    printf("%d\n",mn++);
    return 0;
}

options:
A. 8
B. 7
C. 6
D. compiler error


Ques 9. what is the output for the below code?
#include <stdio.h>
#include <stdlib.h>
int main()
{
    int mn=5,y,z,s;
    mn = (y=mn++) + (z=mn++) + (s=++mn);

    printf("%d\n",mn++);
    return 0;
}

options:
A. 19
B. 21
C. 22
D. compiler error


Ques 10. what is the output for the below code?
#include <stdio.h>
#include <stdlib.h>
int main()
{
    int mn=5;
    mn = mn++ + mn-- + --mn;

    printf("%d\n",mn++);
    return 0;
}

options:
A. 16 
B. 14
C. 15
D. compiler error



Ques 11. what is the output for the below code?

#include <stdio.h>
#include <stdlib.h>
int main()
{
    int mn=5, y=3;

    printf("%d\n",mn>y? 22:44);
    return 0;
}
options:
A. 44
B. 22
C. 5
D. 3



Ques 12. what is the output for the below code?

#include <stdio.h>
#include <stdlib.h>

int fun(int *m, int *n)
{
    int sub = *m-*n;
    *m=*n;
    return *m+*n;

}
int main()
{
    int *a,*b;
    int x=22,y=3;

    a=&x; b=&y;

    printf("%d\n",fun(a,b));
    return 0;
}

options:
A. 6
B. compiler error
C. 22
D. 8



Ques 13. what is the output for the below code?

#include <stdio.h>
#include <stdlib.h>

int fun(int *m, int *n)
{
    int sub = *m-*n;
    *m=*n;
    return *m+*n;

}
int main()
{
    int *a,*b;
    a=(int *)malloc(4);
    b=a;

    *a=3; *b=5;

    printf("%d\n",fun(a,b));
    return 0;
}
options:
A. 8
B. 10
C. 13
D. compiler error


Ques 14. what is the output for the below code?

#include <stdio.h>
#include <stdlib.h>

void fun(int **m, int **n)
{
    int t = *m;
    *m=*n;
    *n=t;
}
int main()
{
    int *a,*b;
    a=(int *)malloc(4);
    b=a;

    *a=3; *b=5;
    fun(&a,&b);

    printf("%d %d\n",*a, *b);
    return 0;
}

options:
A. 3 5
B. 5 3
C. 5 5
D. compiler error


Ques 15. what is the output for the below code?

#include <stdio.h>
#include <stdlib.h>

void fun(int **m, int **n)
{
    int t = *m;
    *m=*n;
    *n=t;
}
int main()
{
    int *a,*b;
    a=(int *)malloc(sizeof(int)*2);
    b=a;

    *a=3; *b=5;
    *a = *b && fun(&a,&b);

    printf("%d %d\n",*a, *b);
    return 0;
}

options:
A. compiler error
B. 1 5
C. 5 5
D. 5 1


Ques 16. what is the output for the below code?

#include <stdio.h>
#include <stdlib.h>

int fun(int **m, int **n)
{
    int t = *m;
    *m=*n;
    *n=t;
    return *m=*n;
}

int main()
{
    int *a,*b;
    a=(int *)malloc(sizeof(int)*2);
    b=a;

    *a=3; *b=5;
    *a = *b && fun(&a,&b);

    printf("%d %d\n",*a, *b);
    return 0;
}

options:
A. compiler error
B. 1 1
C. 5 5
D. 3 3 


Ques 17. what is the output for the below code?

#include <stdio.h>
#include <stdlib.h>

int main()
{
    int a,b;

    a=3; b=5;
    b = sizeof( a *= b+5);

    printf("%d %d\n",a, b);
    return 0;
}

options:
A. 3 5
B. 3 20
C. 3 4
D. compiler error

Ques 18. what is the output for the below code?

#include <stdio.h>
#include <stdlib.h>

int main()
{
    int a,b,c, d;
    a = 5; b=4; d=7;

    c=a & b | d;

    printf("%d \n", c);
    return 0;
}

options:
A. 7
B. 5
C. 4
D. compiler error



Ques 19. what is the output for the below code?

#include <stdio.h>
#include <stdlib.h>

int main()
{
    int a,b,c, d, e=6;
    a = 5; b=4; d=7;

    c=a & b | d ^ e;

    printf("%d \n", c);
    return 0;
}

options:
A. 4
B. 7
C. 5
D. compiler error

Ques 20. what is the output for the below code?

#include <stdio.h>
#include <stdlib.h>

int main()
{
    int a,b,c, d, e=2;
    a = 5; b=4; d=7;

    c=a >> b | d << e;

    printf("%d \n", c);
    return 0;
}

options:
A. 22
B. 28
C. 7
D. compiler error




Answers

1. A 2. B 3. C 4. D 5. B 6. B 7. C 8. C 9. A 10. C 11. B 12. A 13. B 14. C 15. A 16. B 17. C 18. A 19. C 20. B

Misc QA

MiSC QA



Ques 1. what is token? 

A. each and every units in c program are called tokens .
B. only variables
C. only constants
D. only function names


Ques 2. what are different types of token?




Ques 3. count number of tokens in the below code statement?

scanf("%d", &x);
options:
A. 7
B. 3
C. 6
D. 5


Ques 4. what type of language is c?

options:
A. it is high level language
B. it is low level language
C. it is a high level language with support to low level programming
D. it is super high language



Ques 5. if character size is 1 byte predict the output?

#include <stdio.h>
#include <stdlib.h>
char printchar()
{
  putchar('D');
  return 'D';
}
int main()
{
    printf("%d", sizeof(printchar()));

    return 0;
}

options:
A. 1
B. D 1
C. 1 D
D. compiler error


Ques 6. what is the output for the below code?
#include <stdio.h>
#include <stdlib.h>
int main()
{
int arr[][4] = {1,2,3,4,5,6,7,8} ;
int (*p)[4] = arr;

printf("%d, %d ", *((*p)+1), *((*p)+2));
++p;
printf("%d, %d ", (*p)[1], (*p)[2] );

    return 0;
}

options:
A. 2,3, 6,7
B. 1,2,3,4
C. 5,6,7,8
D. 1,2,5,6 


Ques 7. what is the answer for the for loop line in the below code?
#include <stdio.h>
#include <stdlib.h>

main()
{
 int index;
for(index=0, index<5, index++);
}

options:
A. lexical error
B. only syntax error
C. No compiler error
D. both lexical and syntax error


Ques 8. In C program when the macro defined is resolved?

options:
A. preprocessing time
B. compiling time
C. during linking
D. run time


Ques 9. In C program two files f1 and f2 are present, a funtion present in f2 is called in file f1.
when this is resolved?

options:
A. preprocessing time
B. compiling time
C. during linking
D. run time



Ques 10. In C program a variables declared defined, when this is resolved?

options:
A. preprocessing time
B. compiling time
C. during linking
D. run time


Ques 11. for the below code what is the right way of accessing the data?

int x,y,z;
int *mdn[4], xrg[2][3];

options:
A. mdn[1] = &x, xrg[1]=34
B. mdn[1] = &x, xrg[1][0]=34
C. mdn[4] = &x, xrg[3]=34
D. mdn[1] = &x, xrg[4]=34


Ques 12. what is the option correct for c language?

options:
A. it case insensitive language
B. a regular language
C. it case sensitive language
D. low level language


Ques 13. how the c language processing happen?

options:
A. preprocessing, compilation, linking
B. compilation, preprocessing, linking
C. linking, compilation, preprocessing
D. linking , preprocessing, compilation


Ques 14. what is the command for getting preprocessed file in linux?

options:
A. gcc -k filename.c
B. gcc -E filename.c
C. gcc -l filename.c
D. gcc -p filename.c


Ques 15. what is the command for getting object code file in linux?

options:
A. gcc -S filename.c
B. gcc -E filename.c
C. gcc -o filename.c
D. gcc -c filename.c


Ques 16. what is the command for getting assembly code file in linux?

options:
A. gcc -S filename.c
B. gcc -E filename.c
C. gcc -o filename.c
D. gcc -c filename.c


Ques 17. what is the command for getting outputfile after linking files in linux?

options:
A. gcc -S filename.c
B. gcc -E filename.c
C. gcc -o filename.c
D. gcc -c filename.c


Ques 18. what is the output for the following program?

#include <stdio.h>
#include <stdlib.h>

int disp(int m, int n)
{
    int p=m+n;
    printf("\n m = %d", m);
    return p;
}
int main()
{
    int p=3,q=4, k;
   int (*f)(int, int);
    f=disp;
    k=f(p,q);
printf("\n k= %d",k);
    return 0;
}

options:
A. 3 7
B. compiler error
C. runtime error 
D. 7 7 


Ques 19. what is the output for the following program?

#include <stdio.h>
#include <stdlib.h>

int main()
{
    int p=0x55 ;
    p = 0xb>>1<<2;
    printf("\n p= %x",p);
    return 0;

}

options:
A. a8
B. compiler error
C. runtime error 
D. 14 


Ques 20. what is the output for the following program?

#include <stdio.h>
#include <stdlib.h>

int main()
{
    int p=0x55 ;

     p = (p & 0xff) & (~(1<<2)) ;

     printf("\n p= %x",p);

    return 0;
}


options:
A. 51
B. 54
C. 58
D. 55 



Answers

1. A 2. the different types of tokens are Keywords (ex. int float while, case), Identifiers(ex. main, sum, total), Contants(ex, 44,67) strings (ex: "sum", "welcome", "ptinstitute.in" ) Special symbols (ex: (), {}) Operators (ex: +,-,/, *) 3. 7 4. C 5. 1 6. A 7. B 8. A 9. C 10. B 11. B 12. C 13. A 14. B 15. C 16. A 17. C 18. A 19. D 20. A

Interview Q & A

Interview QA



1. What is Recursion ? 
	A function calling to itself is called recursion. 
Some time stack may overflow if we are not properly exit the recursion function.
stack may overflow if the recursion function calling chain goes very long.
so the runtime error will occur.

ex:
main()
{
int sum;
sum=add(a,b);

}

add(int a, b)
{
int sum=0;
sum = a+b;
if (a>100)
return sum;

add();

}



2. What is stack overflow.?
	stack going outside its maximum range is called stack overflow.
say if stack size 1000 bytes, if the program is writing after 1000 bytes
memory reservered for stack is called stack overflow.
due to this runtime error will occur.



3. what is itoa() function?

  itoa() converts integer to character.

Ex: 
int x=222 
char buf[20]
iota(x,buf, 10); //decimal number to string
iota(x,buf, 2); //binary number to string
iota(x,buf, 16); //hexadecimal number to string


	
4. what is atoi() function?
  atoi function converts string to integer.

ex:
char str="32322";
num=atoi(str);



5. write your own funtion itoa(), atoi() ?



6. what is bigendian?

  	The  data present in the variable, if it stores Higher byte first in memory is called bigendian.
ex: var =0x44556677 

in memory it stores first 44 then --55 --66 --77
ex: 0xffff0000 = 44
    0xffff0001 = 55
    0xffff0002 = 66
    0xffff0003 = 77 



7. what is little endian?

  	The  data present in the variable, if it stores Lower byte first in memory is called little endian.
ex: var =0x44556677 

in memory it stores first 77 then --66 --55 --44

ex: 0xffff0000 = 77
    0xffff0001 = 66
    0xffff0002 = 55
    0xffff0003 = 44 



8. What is memory leak?
   If the memory is allocated using malloc, calloc etc after using it has to be freeed
if that memory is not used more.

if that memory is not freeed then it is called memory leakage.



9. Segmentation fault?
It is caused by the program writing and reading memory in illegal memory location is called segmentation fault.
say a read only location, or writing the non existing array element.
it causes the runtime error.



10. Dangling pointer?
   If a pointer is allocated a memory then after using it is deallocated. 
The pointer still pointing to the same meory location, but it is unreserved for it now.
if this pointer is accessed then unpredictable behavior accours, this is called dangling pointer .
it causes runtime error.



11. what is token?

each word say keyword, symbols, variables, ; , etc in a c program is called token.
there are 6 types of token
 
  - keywords  ex: int, float, switch, case, if, else etc
  - operators ex: +, -, *, /, %, |, &, ^, || etc
  - strings  ex: "sum = %d, avg= %f", "total = " 
  - Identifiers(ex. main, sum, total), 
  - Contants(ex, 44,67)
  - Special symbols (ex: (), {})



12. what is forward reference?

    Refering to the label before its declaration is called forward reference.


goto SUM;

SUM:
 ------
 -----

En-Query

Your Name*
Subject*
Phone Number*
Email Address*

Message*