String Q & A

String Q-A



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

#include <stdio.h>
#include <stdlib.h>
void ustrcpy(char *d, char *s);

int main()
{
   char name1[15] ="hello";
   char name2[15] ="ptinstitute.in";
   ustrcpy(name1, name2);
   printf("\n %s", name2);

   return 0;
}

void ustrcpy(char *d, char *s)
{
    d=s;
}
options:
A. ptinstitute.in
B. compiler error
C. runtime error
D. not print anything



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

#include <stdio.h>
#include <stdlib.h>
void ustrcat(char d[], char s[]);

int main()
{
    char name1[15] = "good";
    char name2[15] ="ptinstitute.in";
    ustrcat(name1, name2);
    printf("\n %s", name1);
    return 0;
}

void ustrcat(char d[], char s[])
{
    int len1, len2,i;
    len1=strlen(d);
    len2=strlen(s);
    for(i=len1; i

Ques 3. what is the output for the below code?
#include <stdio.h>
#include <stdlib.h>
int main()
{
    char name1[] = {'g', 'o', 'o', 'd'};
    char name2[] ="ptinstitute.in";

    printf("\n %d %d", sizeof(name1), sizeof(name2));
    printf(" %d", sizeof(name1[1]));
    return 0;
}

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


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

#include <stdio.h>
#include <stdlib.h>
void ustrcpy(char *, char *);

int main()
{
    char name1[15];
    char name2[] ="ptinstitute.in";
    ustrcpy(name1, name2);
    printf("\n name1 = %s", name1);
    printf(" name2 = %s", name2);
    return 0;
}

void  ustrcpy(char *d, char *s)
{
    int i;
    for(i=0; i

Ques 5. what is the output for the below code?
#include <stdio.h>
#include <stdlib.h>
int main()
{
    char name1[] = {'g', 'o', 'o', 'd','j','k'};
    char name2[] ="ptinstitute.in";

    int ii[]={2,3,4,5,6,7,8};

    printf("\n %d %d", sizeof(name1), sizeof(name2));
    printf(" %d", sizeof(&name1));

    return 0;
}

options:
A. 7 15 4
B. compiler error 
C. 4 4 4
D. 6 15 4


Ques 6. what is the output for the below code?
#include <stdio.h>
#include <stdlib.h>
char *str;
void fun(char *s);

int main()
{
    strcpy(str, "ptinstitute.in");
    fun(str);
    printf("\n %s",str);
    return 0;
}

void fun(char *s)
{
    printf(" %s",s);
}

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


Ques 7. what is the output for the below code?
#include <stdio.h>
#include <stdlib.h>
void fun(char *s);
int main()
{
    char *s1 = "hello";
    char *s2= "good";

    while(s1!= s2)
    fun(s1);

    return 0;
}

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

options:
A. compiler error
B. Infinite loop
C. hello
D. good


Ques 8. what is the output for the below code?
#include <stdio.h>
#include <stdlib.h>
int main()
{
    char *s1 = "hello";
    char *s2 = "good";
    printf("\n %d", s2-s1);
    return 0;
}

options:
A. 6
B. 111
C. o
D. compiler error


Ques 9. what is the output for the below code?
#include <stdio.h>
#include <stdlib.h>
int main()
{
    char s1[] = "welcome";

    char *s2=s1;
    s2 =s2[1] -s2[3];
    printf("\n %s",s2);

    return 0;
}

options:
A. runtime error
B. compiler error
C. 2
D. lcome


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

#include <stdio.h>
#include <stdlib.h>
int main()
{
    char s1[] = "welcome";

    printf("\n %s %s",&s1[1], &s2[2]);

    return 0;
}

options:
A. run time error
B. elcome lcome
C. compiler error
D. welcome welcome
  

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

#include <stdio.h>
#include <stdlib.h>
int main()
{
    char s1[] = "welcome";
    printf("\n %c %c %c",*(s1+1), s1[2], 3[s1]);
    return 0;
}

options:
A. compiler error
B. e l c
C. runtime error
D. elcome lcome come


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

#include <stdio.h>
#include <stdlib.h>
int main()
{
    char s1[] = "welcome";
    printf("\n %s %s", s1+3, s1+s1[1]-s1[6]);
    return 0;
}


options:
A. welcome welcome
B. come welcome
C. compiler error
D. runtime error


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

#include <stdio.h>
#include <stdlib.h>
int main()
{
    char s1[1][1][2][4] = {'w', 'e', 'l', 'c', 'o', 'm', 'e', '

Ques 13. what is the output for the below code?
#include <stdio.h>
#include <stdlib.h>
int main()
{
char s1[1][1][2][4] = {'w', 'e', 'l', 'c', 'o', 'm', 'e', '\0'};
printf("\n %s ", ***s1);
return 0;
}
options:
A. welcome
B. compiler error
C. runtime error
D. welcom
'}; printf("\n %s ", ***s1); return 0; } options: A. welcome B. compiler error C. runtime error D. welcom

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

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{
    int i=0;
    int len;
    char *s1 = "welcome";
    char *p;

    p=(char *)malloc(10);
    len=strlen(s1);

    do{
        p[i] = s1[++i];
    }
    while(i

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

char * changecase(char *s2)
{
    char *t= (char *)malloc(15);
    int i;

    for(i=0; i<15; i++)
    {
        if(s2[i] >= 65 && s2[i]<97)
            t[i]=s2[i]+32;
        else
            t[i]=s2[i];
    }
    t[i]=0;
    return t;
}

int main()
{
    char *s1 = "PTINSTITUTE.IN";
    char *t=changecase(s1);
    printf("\n %s", t);
    return 0;
}

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


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

#include <stdio.h>
#include <stdlib.h>
void swap(int *p, int *q)
{
    int  t=*p;
    *p=*q;
    *q=t;
}

int main()
{
    int p=33, q=55;
    swap(&p,&q);

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

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



Answers

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

Structure and Union

Structure and Union


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

typedef struct str{
char * name[2]={"welcome", "good"};
int x=333;
float y=98.878;
char * name;
}p;

int main()
{
    p s1;

    printf("\n %s", s1.name[0]);
    printf(" %d", s1.x);

    return 0;
}

options:
A. welcome 333
B. good 333
C. Compile time error
D. ruin time error



Ques 2. what is the output for the following c program ?
#include <stdio.h>
#include <stdlib.h>

typedef struct str{
static int x;
float y;
}pstr;

int main()
{
    pstr p;
    p.x=32;
    p.y=22;
    printf("\n %d", p.x);
    printf("\n %f", p.y);

    return 0;
}

options:
A. compile time error
B. 32 22
C. run time error
D. 22 32


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

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

union un{
int x;
float y =3434;
}uvar;

int main()
{
    uvar.x=0x33ff;

    printf("\n %x", uvar.x);
    printf("\n %f", uvar.y);

    return 0;
}

options:
A. 0x33ff, 3434
B. compile time error
C. 0x33ff 0.000
D. run time error


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

union un{
int x;
char y ;
char z;
}uvar;

int main()
{
    uvar.x=0x3334;
    uvar.y = 'A';
    printf("\n %x", uvar.x);
    printf("\n %c", uvar.y);
    printf("\n %c", uvar.z);

    return 0;
}
options:
A. 0x3334 A,A
B. 0X0A0A A,A
C. 0X3341 95 95
D. 0X3341 A A 


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

union un{
int x;
char y ;
char z;
}uvar;

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

options:
A. 6
B. 4
C. 8
D. 10


Ques 6. what is the output for the below code?
#include <stdio.h>
#include <stdlib.h>
struct st{
    int y;
union un{
int x;
char m ;
char z;
}unvar;
};
int main()
{
    struct st svar;

    svar.unvar.x=0x1244;
    svar.y=0x4567;

    printf("\n 0x%x", svar.y);
    printf("\n 0x%x", svar.unvar.x);
    printf("\n %c", svar.unvar.m);
    printf("\n 0x%x", svar.unvar.z);
    return 0;
}

options:
A. compiler error
B. runtime error
C. 0x4567 0x4567 g 67
D. 0x4567 0x1244 D 0x44


Ques 7. what is the output ?
#include <stdio.h>
#include <stdlib.h>

struct st{
    int y;
union un{
int x;
char m ;
char z;
}unvar;
};
int main()
{
    struct st svar;

    printf("\n %d %d", sizeof(struct st), sizeof(union un));
    return 0;
}


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


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

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

struct st{
    int y[4];
union un{
double x;
long m ;
char z[8];
}unvar;
};
int main()
{
    struct st svar;

 printf("\n 0x%x 0x%x", sizeof(struct st), sizeof(union un));

    return 0;
}
options:
A. compile time error
B. 0x18 0x18
C. 0x18 0x8
D. runtime error



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

#include <stdio.h>
#include <stdlib.h>
typedef struct st {

    float average;
    struct st ptr;
}svar;
int main()
{
    svar sv;
    sv.average=99.44;
    sv.ptr=sv;
    printf("\n %f", sv.ptr.average);

    return 0;
}

options:
A. copile time error
B. run time error
C. 99.44
D. 99.00


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

#include <stdio.h>
#include <stdlib.h>
typedef struct st {

    float average;
    char y;
}svar;
int main()
{
    svar s1, s2;
    s1.average=99.44;
    s2.average=99.44;
    if(s1==s2)
    printf("\n %d", s1.average);
    printf("\n struct var compare");
    return 0;
}

options:
A. 99
B. struct var compare
C. 99.44
D. compile time error


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

#include <stdio.h>
#include <stdlib.h>
union un {

    char arr[4];
    int avg;
}u1;
int main()
{

    u1.avg=0;
    u1.arr[2]='F';
    u1.arr[3]='E';
    printf("\n %s", u1.arr);


    return 0;
}

options:
A. 0FE
B. nothing is printed
C. Compile time error
D. Garbage characters


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

#include <stdio.h>
#include <stdlib.h>
union un {

    char arr1[7];
    char arr2[7];    
}u1;
int main()
{
    strcpy(u1.arr1, "good");
    strcpy(u1.arr1, u1.arr2);
    u1.arr2[4]='b';
    printf("\n %s", u1.arr1);
    printf(" %s", u1.arr2);

    return 0;
}

options:
A. good goodb
B. compile time error
C. good bgood
D. run time error


Ques 13. If the system is little endian what is the output ?

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

union un {

    char arr1[2];
    short svar;
}u1;
int main()
{
    u1.svar=0x4567;
    printf("\n 0x%x", u1.svar);
    printf(" 0x%x 0x%x", u1.arr1[0], u1.arr1[1]);

    return 0;
}


options:
A. 0x4567 0x67 0x45
B. 0x4567 0x45 0x67
C. runtime error
D. 0x4567 g E


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

#include <stdio.h>
#include <stdlib.h>
union un {
    int x;
    short svar;
}u1;
int main()
{
    register int i=0;
    u1.x=0x4;
    u1.svar = 0x2;
    for(i=0; i<5; i++)
    u1.svar /= 0x2*i;
    printf("\n 0x%x", u1.svar);

    return 0;
}

options:
A. runtime error
B. compile time error
C. 0
D. 0.5


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

#include <stdio.h>
#include <stdlib.h>
struct st {

    int m,n,p;
}svar= {3, 5, 8};
int main()
{
    svar.m+=2;
    svar.n+=2;
    svar.p+=2;

    printf("\n %d %d %d ", svar.m, svar.n, svar.p);
    return 0;
}

options:
A. 3 5 8
B. runtime error
C. 5 7 10 
D. Compile error



Answers

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

Macro Pre-processor

Macro PreProcessor


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

#define min(x, y) x < y? x : y
int main()
{
    int x=2, y=33, z;
    z=min(x, y);

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

options:
A. 2
B. 33
C. compile time error
D. run time error



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

#include <stdio.h>

#define BIT

int main()
{
    #ifdef BIT
        printf("\n BIT ");
    #elif
        printf("\n BYTE);
    #else
        printf("\n word);
    #endif

    return 0;
}

options:
A. BIT
B. BYTE
C. word
D. compile time error


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

#define BYTE

#if BIT
    #define BIT 1
#else
    #define BYTE 8
#endif


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

options:
A. 1
B. 8
C. runtime error
D. Compile time error


Ques 4. what is the output for the below code?
#include <stdio.h>
#define xy(x,y) x##y

int main()
{
    printf("\n XY = %d" ,xy(2,3));
    return 0;
}


options:
A. 2
B. 3
C. 23
D. compile time error


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

#define M 3

#if M
    printf("\n ptinstitute.in");
#else
    printf("\n welcome");
#endif

int main()
{
    return 0;
}

options:
A. Compile time error
B. ptinstitute.in
C. welcome
D. run time error


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

#include <stdio.h>
#define MAX(a,b)  a>b?a:b

int main()
{
    int a=2,b=3,c=4,d=6,z;

    z=MAX(a+b, c+d);
    printf("\n z=%d",z);

    return 0;
}

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


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

#define setbit(x,bitno)  x=(x | (1<<bitno))

int main()
{
    int a=0x3;

    setbit(a, 3);
    printf("\n a=%x",a);

    return 0;
}

options:
A. b
B. 11
C. 31
D. compile time error


Ques 8. what is the output ?
#include <stdio.h>

#define resetbit(x,bitno)  x=(x & ~(1<<bitno))

int main()
{
    int a=0x1f;

    resetbit(a, 2);
    printf("\n a=%x",a);

    return 0;
}
options:
A. compile time error
B. 2f
C. 1f
D. 1b



Ques 9. what is the output for the below code?
#include <stdio.h>
#define togglebit(x,bitno)  x=(x ^ (1<<bitno))

int main()
{
    int a=0x1b;

    togglebit(a, 2);
    printf("\n a=%x",a);

    return 0;
}

options:
A. 1c
B. 1b
C. 1f
D. 1d


Ques 10. what is the output for the below code?
#include <stdio.h>
#define cube(x) x*x*x

int main()
{
  int x=3;
  x = 9/cube(x);
  printf("%d", x);
  return 0;
}

options:
A. 0
B. 27
C. 0.333
D. compile time error


Ques 11. what is the output?

#include <stdio.h>
#define compute(x) x*x+3  x++
int main()
{
  int x=3;
  x = compute(x);
  printf("%d", x);
  return 0;
}

options:
A. 13
B. 12
C. Compile time error
D. run time error


Ques 12. what is the output?
#include <stdio.h>
# define getch  "%s Good morning "
int main()
{
   printf(getch, getch);
   return 0;
}

options:
A. %s Good morning %s Good morning 
B. run time error
C. Compile time error
D. %s Good morning Good morning 


Ques 13. what is the output for the below code?
#include <stdio.h>
#define ABC 10
#define ABC 22

int main()
{
  printf("%d ",ABC);
  #define ABC 33
  printf("%d ",ABC);

  return 0;
}

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


Ques 14. what is the output for the below code?
#include <stdio.h>
#define len(len,gth) len##gth
int main()
{
   int length = 100, breadth=4,a;
   a=len(len, gth)* breadth;
   printf("%d", a);
   return 0;
}
options:
A. 400
B. compile time error
C. run time error
D. 25


Ques 15. what is the output for the below code?
#include <stdio.h>
#define abc(x,y) x+y * x-y
int main()
{
   int a;
   a=abc(3,4);
   printf("%d", a);
   return 0;
}

options:
A. 11
B. -7
C. -1
D. 17



Answers

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

Array I

Array I


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

int main()
{
   char *arr[4]={"hello", "good", "bad", "yes" };
    char *chptr;
    chptr=arr;
    chptr++;

    printf("\n chptr = %s", *chptr);

    return 0;
}

options:
A. good
B. hello
C. bad
D. run time error


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

int main()
{

    char *arr[4]={"hello", "good", "bad", "yes" };
    char **chptr;
    chptr=arr;
    *chptr++;

    printf("\n chptr = %s", chptr[1]);
    return 0;

}
options:
A. hello
B. bad
C. good
D. run time error



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

#include <stdio.h>
#include <stdlib.h>
int main()
{
    int iarr[5] = {2,3,4,5,6};

    printf("\n chptr = %d  %d", *(iarr+1) , *(*(&iarr)+1));
    return 0;
}

options:
A. 3 2
B. 2 2
C. 3 3
D. compile time error



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

#include <stdio.h>
#include <stdlib.h>
int main()
{
    int inum[5] = {2,3,4,5,6};

    printf("\n chptr = %d  %d", sizeof(inum), sizeof(inum[0]));
    return 0;
}

options:
A. 4 4
B. 20 4
C. 20 20
D. compile time error



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

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

int main()
{
    int s[5] = {32,23,43,52,16};
    int *p=(&s+1);
    p-- ;

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

options:
A. 16
B. 32
C. 23
D. compile time error


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

void fun(int ar[])
{
    printf("%d\n", ar[4]);
}

int main()
{
    int ar[5] = {32,23,43,52,16};

    fun(ar);
    return 0;
}

options:
A. 16
B. 32
C. 43
D. compile time error


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

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

void fun(int ar[])
{
    printf("%d\n", ar[2]);
}

int main()
{
    int ar[5] = {32,23,43,52,16};
    fun(ar[2]);
    return 0;
}

options:
A. 43 
B. 16 
C. 52
D. run time error


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

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

void fun(int arr[])
{
    printf("%d\n", arr[3]);
}

int main()
{
    int numarr[5] = {2,3,4,15,23,4,6};
    fun(&numarr[1]);
    return 0;
}

options:
A. 15 
B. compiler error
C. 23
D. 15


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

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

void fun(int arr[])
{
    int k;
    if(k=1)
     printf("%d\n", arr[0]);
    else
     printf("%d\n", arr[3]);

}

int main()
{
    int narr[5] = {2,3,4,15,23,4,6};
    fun(narr);
    return 0;
}

options:
A. 15
B. 2
C. 4
D. compiler error


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

int main()
{
    int x,y,z,e,f;
    int *narr[5] = {&x,&y,&z,&e,&f};
    int marr[2][2] ={5,6,7,8} ;

    narr[1] = 1000;

    printf("%d %d  \n", narr[1],marr[1][1]);
    return 0;

}
options:
A. compile time error
B. run time error
C. 1000 8
D. 6 



Answers

1. D 2. B 3. C 4. B 5. A 6. A 7. D 8. C 9. B 10. C

C Loops & Control – I

 

C Loops & Control - I



Ques. 1: What will be the output result of below code?

#include 
 
int main()
{
    int i = 2048;
    for (; i; i >>= 1)
        printf("Embedded system training");
    return 0;
}
How many times Embedded system training will appear
A. 11
B. 12
C. code will not compile.
D. infinite loop.



Ques. 2: What will be the output result of below code?

#include 
int main()
{
    int i = 10;
    switch (i)
    {
        case '10': printf("Professional");
                break;
        case '11': printf("Training");
                break;
        default: printf("Institute");
    }
    return 0;
}

A. Professional  
B. Training
C. Institute
D. Compile time error.



Ques. 3: consider following code, what is the output?

#include
int add(){
printf("don't add here ");
return 0;
}

int main()
{
       int i=1024;
       if (add(i))
       {
       i=9;
       }else
       {
       i=12;
       }
       printf("%d",i);

       return 0;
}

A. don't add here 9
B. don't add here 12
C. error while compile
D. 12



Ques. 4: find the output

#include
main()
{
    int check=0;
    if (check);
    else
    {
         printf("Hello PTI");
    }
    printf(" see you soon.\n");
}

A. Hello PTI see you soon.
B. else without a previous if
C. see you soon
D. none of above



Ques. 5: find the output

#include
main()
{
    int check=0;
    if (check);
    {

    }
    else
    {
         printf("Hello PTI");
    }
    printf(" see you soon.\n");
}

A. Hello PTI see you soon.
B. else without a previous if
C. see you soon
D. none of above



Ques 6: What is the output?
 
#include  
#define DISP(i, limit) do \ 
                        { \ 
                            if (i++ < limit) \ 
                            { \ 
                                printf("PTinstitute\n"); \ 
                                continue; \ 
                            } \ 
                        }while(0) 
  
int main() 
{ 
    int i = 0; 
    DISP(i, 3); 
    return 0; 
} 

A. 0
B. PTinstitute
C. 3
D. Compile time error


Ques 7. what is the output?

#include 
int main()
{
    int i = 4;
    switch (i)
    {
        case 1+0: printf("PTI");
                break;
        case 2+2: printf("Good");
                break;
        default: printf("Test");
    }
    return 0;
}

A.  PTI
B.  Good
C.  Test
D.  none of the above



Ques 8: find the outpout?

#include 
#define TRUE 1
#define FALSE 0

int main()
{
    int i = 3;

    switch (i & 1)
    {
        case FALSE: printf("FALSE");
                break;
        case TRUE: printf("TRUE");
                break;
        default: printf("Default");
    }
    return 0;
}

A. TRUE
B. FALSE
C. Default
D. None of the above



Ques 9: find the outpout?

#include 

enum num{FALSE, TRUE };

int main()
{
    int i = 3;

    switch (i & 1)
    {
        case FALSE: printf("FALSE");
                break;
        case TRUE: printf("TRUE");
                break;
        default: printf("Default");
    }
    return 0;
}

A. Default
B. FALSE
C. TRUE
D. None of the above




Ques 10: find the outpout?

#include 
int main()
{
    int m;
    if (printf("0"))
        m = 3;
    else
        m = 5;
    printf("%d", m);

    return 0;
}

Options:

A. 05
B. 03
C. 5
D. Compile time error


Ques 11: find the outpout?

#include
int main()
{
   int k;
   for (k = 5; k!=0; k--)
     printf("n = %d", k--);
   return 0;
}

Options:
A. n = 5 n= 3 n=1 
B. n= 5, n= 4, n= 3 n=2 n=1
C. Infinite loop
D. 5 4 3 2 1


Ques 12: find the outpout?

#include 
int main()
{
    int g = 4, num = 8;
    do {
        num /= g;
    } while(g--);

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

options:
A. 1
B. 0
C. Runtime error
D. Compile time error

Ques 13: find the outpout?

#include 
int main()
{
    int g = 4, num = 8, true=1;
    do {
        num = num / g;
        true --;
    } while(true);

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

options:
A. 1
B. 0
C. 2
D. Compile time error


Ques 14: find the outpout?

#include 
int main()
{
    int h = 4, y= 8;
    if(y/h==2)
        printf("\n h=2");
    else
        printf("\n h!=2");

    return 0;
}
options:
A. h=2
B. h!=2
C. Compiletime error
D. none of the above


Ques 15: find the outpout?

#include 
int main()
{
    int m = 1;
    if(m)
        {
            m--;
            printf("\n %d ", m);
            if(!m)
                printf("%d ",m );
            else
                printf("%d ",m);
        }
    else
        printf("\n h!=2");

    return 0;
}

options:
A. 1 1
B. 0 0
C. Compiletime error
D. 1 0

Answers

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

 

Pointer Test I


Pointer Test I

 


Ques. 1: If a variable is a pointer to a structure, then what is the operator to
     access data members of the structure through the pointer variable?

A. dot operator(.)	 
B. address operator(&)
C. indirection operator(*)	
D. -> operator


Ques. 2: What will be the output result of below code?

#include
main()
{
    float x = 13.442;
    int *w = x;
    printf("%d",*w);
}

A. 10	                        
B. 10.2
C. error: incompatible type	
D. no output



Ques. 3: The operator used to access the value of variable at address stored in a pointer variable is?

A. indirection operator(*)
B. address operator(&)
C. dot operator(.)	
D. logical And operator(&&)



Ques. 4: What will be the output of following code assuming that array begins at location 1002?

#include
main()
{
    int m[5] = {5, 6,7, 8, 9};
    int *s = m;
    printf("%d\t%d\t%d\t%d\t",*s,0[m],m,s);
}
A. error	
B. 5 5 1002 1002
C. 5 0 1002 0	
D. 5 5 0 1002



Ques. 5: What will be the output of following code?

#include 
int iarr[] = {1,2,3};
main()
{
    int *qptr; 
    qptr = iarr;
    qptr = qptr+3;
    printf("%d",*qptr);
} 
A. error
B. 3
C. 2
D. garbage value



Ques. 6: What is the output of below code?

#include 
void main()
{
    int const *ptr = 5;
    printf("%d", ++(*ptr));
}
A. error	
B. 5
C. 6	
D. print address of p



Ques 7: What will be the output of following code?

#include
main()
{
    struct std
    {
        int a = 3;
        char str[] = "hello";
    };
    struct std *ptr;
    printf("%d", ptr->x);
    printf("%s", ptr->name);
} 

A. 3 hello
B. garbage value
C. error in declaration of pointer to structure.
D. error because of initializing variables in structure declaration



Ques. 8: What will be the output of following code?

#include 
main()
{
    register a = 5;
    char b[] = "welcome";
    printf("%s %d", b, a);
}
A. error
B. welcome 5
C. welcome
D. none of the above



Ques. 9: What is the size of char on 32-bit machine?
A. 1
B. 2
C. 4
D. 8

Ques. 10: Is the NULL pointer same as an uninitialised pointer?
A. Yes	
B. No



Ques.11: Which of the statement is correct about the code?

int add(int, int);
int (*p)(int, int);
p = add;

A. p is a pointer to a function add which return integer
B. p is a function which return integer pointer
C. p is a function similar to add function
D. none of the above



Ques. 12: What will be the output of following code?

#include 
int fun(int *m,int *n)
{
    *m = *m+*n;
    *n = *m-*n;
    *m = *m-*n;
}

main()
{
    int a = 10,b = 20;
    fun(&a,&b);
    printf("a= %d b = %d\n", a, b);
}
A. x=10 y=20	B. x=20 y=10
C. 20 10	D. error



ques 13: What will be the output of the C program?

#include
int main(){
	   int g = 435;
	char *mptr;
	mptr = (char *)&g;
	printf("%d ",*mptr);
	return 0;
}
A. -77
B. Run Time Error 
C. Garbage value
D. Compile Time Error


ques 14: What will be the output of the C program?

#include
int main(){
	int h = 3;
	int *m;
	int **p;
	m = &h;
	p = &m;
	p++;
	printf("%d ",**p);
	return 0;
}
A. Garbage value
B. Compilation Error 
C. Run time error
D. Linker Error



Ques. 15. What will be the output of the C program?

#include
int main(){
    int a = 24;
	int *b;
	b = &a;
	b++;
	printf("%d ",*b);
}

A. Linker Error 
B. Run time error 
C. Compilation Error 
D. Garbage value 


Ques 16. What will be the output of the C program?

#include
#include
int main(){
	char *str = "welcome";
	char b[22];
	strcpy(b, "ptinstitute");
	printf("\n%s %s",str, b);
	return 0;
}

A. welcome ptinstitute 
B. Run time error 
C. Compilation Error 
D. Garbage value 



Ques 17. What will be the output of the following C program?

#include
#include
int main(){
	char *str1 = "hello";
	char str2[22];
	*str1 = "world";
	printf("\n%s %s",str1, str2);
	return 0;
}
A. Linker Error
B. Run time error
C. Compilation Error
D. Garbage value



Ques 18. What will be the output of the C program?

#include
int main()
{
	char *str = "welcometoworld";
	printf(str + 4);
	return 0;
}
A. ometoworld
B. metoworld
C. welc
D. welco



Ques 19. What will be the output of the C program?

#include
int main()
{
	char *qptr = "goodmorning";
	printf("%c\n",*&*qptr);
	return 0;
}
A. Address of g
B. Compilation Error 
C. g
D. Run time error



Ques 20. What will be the output of the C program?

#include
#include
int main(){
	register y = 23;
	int  *q;
	q = &y;
	printf("%u",q);
	return 0;
}
A. Address of a
B. Run time error 
C. Garbage value
D. Compile time error



Answers

1. D. -> operator 2. C. error: incompatible type 3. A. indirection operator(*) 4. B. 5 5 1002 1002 5. D. garbage value 6. A. error // incrementing the const pointer data *ptr is not allowed 7. D. error because of initializing variables in structure declaration 8. B. welcome 5 9. A. 1 10. B. No // NULL pointer pointing to address 0x0, uninitialised pointer pointing to some unknown location. 11. A. p is a pointer to a function add which return integer 12. B. x=20 y=10 13. A. -77 14. C. Run time error // p is pointer to m, m is a pointer to h. on incrementing the p , //it will points to some garbage value, so it is a runtime error. 15. D. Garbage value // b is pointer variable pionting to variable a. on incrementing b // it points to other location which is not initialised hence gives garbage value. 16. A. welcome ptinstitute 17. C. Compilation Error // str1 is a ponter to character variable, it can be initialised only at declaration. 18. A. ometoworld 19. C. g 20. D. Compile time error // y is a register variable, q is requesting the register address.

Test 1

 

Test I


Ques 1 : What is the output of the below program.
main() 
{ 
    int m=33,n=21; 
    m=m++ + n++; 
    n= ++m + ++n; 
    printf("%d %d",m,n);
}
Options:
(A) 55 78 
(B) 57 80
(C) 58 79
(D) 60 78

Ques 2 : What will be output for program below mentioned:

main() 
{ 
 int s=5; 
	printf("%d,%d,%d",s,s<<3,s>>1);
}

Options:
(A) 5,40,2 
(B) 5,38,3
(C) 4,44,3
(D) 5,40,4



Ques 3 : For the below program what is the correct answer?

main ()
{
 	int m, n, p;
	 m = 2;
	 n =4*(m++);
	 p =3*(++m);
}

Options:
(A) n = 8, p = 12. 
(B) m = 7, p = 13.
(C) n = 9, p = 12.
(D) m = 8, n = 8.



Ques 4 : How many iterations the below loop will run
main()
{
	int k;
	k=0;
	do
	{
		k--;
		printf("%d",k);
		++k;
	}
	while(k>=0);
}

Options:
(A) 77
(B) Infinite 
(C) Compilation Error
(D) 0



Ques 5 : what would be the output if ch = 'D' ?

switch(ch)
{
	case 'D' : printf("Wonder");
	case 'S' : printf("Good");
	case 'R' : printf("Welcome");
	break;
}

Options:
(A) Wonder
(B) WonderGood
(C) WonderGoodWelcome
(D) None of the above



Ques 6 :  x,y,z are integer variables with values 2,4,6 respectively. 
 What is the result of the below expression:   
 !((x+y)>(z+10))

Options:
(A) 1 
(B) 4
(C) 12
(D) 0



Ques 7 : For the below program, How many times "www.ptinstitute.in" printed?

main ()
{
      int e, r;
      for (e=5, r=1; e ==4, r < 10; e --, r++)
		printf("\n www.ptinstitute.in");
}

Options:
(A) 5
(B) compilation error 
(C) 9 
(D) None of the above



Ques 8 : What value will be printed for the program below.

main()
{
	 int f,m,h;
	f=21;
	m=32;
	h=printf("%d",f) + ++m;
	printf("%d",h);
}

Options:
(A) 2133 
(B) 2032
(C) 2135
(D) Compilation Error



9 : How many times the below loop will get executed?
main()
{
	int s;
	for(s=9;s;s=s-4)
	{
		printf("\n%d",s);
	}
}

Options:
(A) 2
(B) 3
(C) Error
(D) Infinite 



Ques 10 : What is the result printed for the below statement if x=12
printf("%d %d",x, !x--);

Options:
(A) 11 0  
(B) 12 12
(C) 12 0
(D) 0 12



Ques 11 : What shall be the output

main()
{
	int e;
	e = 13;
	if(e == 21 || 20)
	{
		printf("Correct");
	}
	else
	{
		printf("Wrong");
	}
}

Options:
(A) Correct 
(B) Worng
(C) Compiler Error
(D) Run time Error



Ques 12 : What is the output for the below program?

main()
{
	if(22,0,23)
	{
		printf("True");
	}
	else
	{
		printf("False");
	}
}

Options:
(A) True  
(B) False
(C) Syntax Error
(D) Compiler Error



Ques 13 : What shall be the output for the below code?

main()
{
	int g, h, *p, *q`;
	g = 10;
	h = 10;
	p = &g;
	q = &h;
	if(p == q)
	{
		printf("one");
	}
	else
	{
		printf("zero");
	}
}

Options:
(A) one
(B) zero   
(C) Compiler Error
(D) Syntax Error



Ques 14 : How many times the for loop will get executed in the below program?

main()
{
	int a;
	for(a=12, a=8; a>=0; a--)
	{
		printf("\n %d", a);
	}
}

Options:
(A) 1
(B) 8
(C) 9  
(D) Syntax Error



Ques 15 : How many iterations main()  will be called?

main()
{
	printf("\n Main function is Called ");
	main();
}

Options:
(A) 100
(B) 1000
(C) 1
(D) Infinite 



Ques 16 : What shall be the output for the program below if the base address of array is 0x2300.

main()
{
	int arr[] = { 5,4,7,8,9 };
	int w,*q ;
	q = arr;
	for(w = 0; w<=4 ; w++)
	{
		printf("\n 0x%x", *q++);
	}
}

Options:
(A) 5 4 7 8 9 
(B) 4 5 8 9
(C) 0x2300 0x2301 0x2302 0x2303
(D) 0x2301 0x2302 0x2303 0x2304


Ques 17 : Which of the following program structure/component/statement is not a concept for implementation of modularization ?

Options:
(A) DLL
(B) Functions
(C) type casting  



Ques 18 : What will be output for the below program?

#include
int main()
{
	 	int i = 340;
	char *q;
	q = (char *)&i;
	printf("%d",*q);

	return 0;
}

Options:
(A) 1
(B) 340
(C) 84 
(D) Syntax Error



Ques 19 : What will be output when you will execute following c  code?

#include
{
	char str[10]="The American King";
	printf("%s", str);
	return 0;
}

Options:
(A) The Americ  
(B) The
(C) Syntax error
(D) None of the aboce


Ques 20 : What is the output result of the below c program?

#include "stdio.h"
int main()
{
	int _ = 3;
	int __ = 13;
	int ___;
	___ = _ + __;
	printf("%i", ___);

}

Options:
(A) 3
(B) 13
(C) 16  
(D) Compilation Error

 

Answers

1. (A) 55 78 2. (A) 5,40,2 3. (A) n = 8, p = 12. 4. (B) Infinite 5. (C) WonderGoodWelcome 6. (A) 1 7. (C) 9 8. (C) 2135 9. (D) Infinite 10. (A) 11 0 11. (A) Correct 12. (A) True 13. (B) zero 14. (C) 9 15. (D) Infinite 16. (A) 5 4 7 8 9 17. (C) type casting 18. (C) 84 19. (A) The Americ 20. (C) 16

En-Query

Your Name*
Subject*
Phone Number*
Email Address*

Message*