Array and Pointer C Programming Mock Test – 5

Question 1
What is the output of the following program?
#include < stdio.h > 
int main()
{
     int a=10, b=20;
     int *p;
     p=&a;
     *p=b;
     a=35;
     *p+=5;
     b=*p;
     p=&b;
     *p=a;
     printf("%d %d",a,b);
     return 0;
}
A
10 20
B
10 40
C
40 40
D
40 10
   C Programming
Question 1 Explanation: 


OUTPUT : 40 40

Click to Join Our Telegram Group for Latest Update of MOCK TEST

Click Here to Practice ALL Previous MOCK TEST FREE

Use Comment Box for your doubts or post similar trickey Questions
Question 2
What is the output of the following program?
#include < stdio.h > 
int main()
{
    int a[]={1,2,3,4,5};
    int b[]={1,2,3,4,5};
    if(a==b)
    {
        printf("IITB");
    }
    else
    {
        printf("IISC");
    }
    return 0;
}
A
IITB
B
IISC
C
Compiler error
D
Output depends on Compiler
   C Programming
Question 2 Explanation: 


If statement will compare the base address of two arrays a and b,and they are not same.
So condition becomes false and program prints no.
OUTPUT : IISC

Click to Join Our Telegram Group for Latest Update of MOCK TEST

Click Here to Practice ALL Previous MOCK TEST FREE

Use Comment Box for your doubts or post similar trickey Questions
Question 3
What is the output of the following program?
#include < stdio.h > 
int main()
{
    int a[5]={1,2,3,4,5};
    int *p;
    p=a;
    printf("%d",*p++);
    printf("%d",(*p)++);
    printf("%d",*p);
    printf("%d",*++p);
    printf("%d",++*p);
    return 0;
}
A
1 2 3 3 4
B
1 2 2 3 4
C
1 2 3 4 4
D
Compiler error
   C Programming
Question 3 Explanation: 


OUTPUT : 12334

Click to Join Our Telegram Group for Latest Update of MOCK TEST

Click Here to Practice ALL Previous MOCK TEST FREE

Use Comment Box for your doubts or post similar trickey Questions
Question 4
What is the output of the following program?
#include < stdio.h > 
int main()
{
    int a[5]={1,2,3,4,5};
    int *p;
    p=a;
    printf("%d",*a++);
    printf("%d",(*a)++);
    printf("%d",*a);
    printf("%d",*++a);
    printf("%d",++*a);
    return 0;
}
A
1 2 3 3 4
B
1 1 2 3 4
C
1 2 3 4 5
D
Compiler error
   C Programming
Question 4 Explanation: 
When we declare int a[5]={1,2,3,4,5}; in c program. "a" becomes the constant pointer. It means that, we can not modify the "a" in program.
In the above program two statements
printf("%d",*a++);
printf("%d",*++a);
tries to modify the "a".
Hence, it's a compiler error.

Click to Join Our Telegram Group for Latest Update of MOCK TEST

Click Here to Practice ALL Previous MOCK TEST FREE

Use Comment Box for your doubts or post similar trickey Questions
Question 5
What is the output of the following program?
#include < stdio.h > 
int main()
{
    int a[5]={1,2,3,4,5};
    int *p;
    p=a;
    printf("%d",*(p+2));
    printf("%d",*(a+2));
    p++;
    printf("%d",*p);
    printf("%d",*a);
    return 0;
}
A
3 3 2 2
B
3 3 2 1
C
3 3 Gabage 1
D
3 3 Gabage 2
   C Programming
Question 5 Explanation: 


OUTPUT : 3321

Click to Join Our Telegram Group for Latest Update of MOCK TEST

Click Here to Practice ALL Previous MOCK TEST FREE

Use Comment Box for your doubts or post similar trickey Questions
Question 6
What is the output of the following program?
#include < stdio.h > 
int main()
{
    int a[5]={1,2,3,4,5};
    int *p;
    p=a;
    printf("%d ",a[-2]);
    printf("%d ",(-2)[a]);
    p=p+3;
    printf("%d ",p[-2]);
    printf("%d ",(-2)[p]);
    return 0;
}
A
3 3 2 2
B
Garbage Gabage Gabage Gabage
C
Garbage Gabage 2 2
D
Compiler error
   C Programming
Question 6 Explanation: 


OUTPUT : Garbage Garbase 2 2

Click to Join Our Telegram Group for Latest Update of MOCK TEST

Click Here to Practice ALL Previous MOCK TEST FREE

Use Comment Box for your doubts or post similar trickey Questions
Question 7
What is the output of the following program?
#include < stdio.h > 
int main()
{
    char a[20]="practicepaper.in";
    char *p;
    p=a;
    p=p+2;
    printf("%s ",a+4);
    printf("%c ",5[a]);
    p=p+3;
    printf("%s ",p+2);
    printf("%c ",p[-3]);
    return 0;
}
A
ticepaper.in i epaper.in a
B
cticepaper.in i cepaper.in a
C
ticepaper.in t epaper.in p
D
Compiler error
   C Programming
Question 7 Explanation: 


OUTPUT : ticepaper.in i epaper.in a

Click to Join Our Telegram Group for Latest Update of MOCK TEST

Click Here to Practice ALL Previous MOCK TEST FREE

Use Comment Box for your doubts or post similar trickey Questions
Question 8
What is the output of the following program?
#include < stdio.h > 
int main()
{
    int x = 5, y = 15;
    int * p1, * p2;
     p1 = &x;
     p2 = &y;
     *p1 = 10;
     *p2 = *p1;
    p1 = p2;
     *p1 = 20;
    printf("%d %d",x,y);
    return 0;
}
A
20 20
B
10 10
C
10 20
D
20 10
   C Programming
Question 8 Explanation: 


OUTPUT : 10 20

Click to Join Our Telegram Group for Latest Update of MOCK TEST

Click Here to Practice ALL Previous MOCK TEST FREE

Use Comment Box for your doubts or post similar trickey Questions
Question 9
What is the output of the following program?
#include < stdio.h > 
int main()
{
    int a[]={1,2,3,4};
    int *p;
    p=a+3;
    *p=5;
    printf("%d",a[3]);
    return 0;
}
A
4
B
5
C
3
D
Compiler error
   C Programming
Question 9 Explanation: 


OUTPUT : 5

Click to Join Our Telegram Group for Latest Update of MOCK TEST

Click Here to Practice ALL Previous MOCK TEST FREE

Use Comment Box for your doubts or post similar trickey Questions
Question 10
What is the output of the following program?
#include < stdio.h > 
int main()
{
     int a, b;
     int c = 5;
     int *p;
     a = 4 * (c + 5) ;
     p = &c;
     b = 4 * (*p + 5) ;
     printf ("%d %d", a, b);
     return 0;
}
A
25 25
B
25 40
C
40 40
D
Compiler error
   C Programming
Question 10 Explanation: 
when we write p=&c in this code, *p and c refere the same location of memory. So if we write c or *p in program both refer the value from same memory location. Hence output is a=40 b=40.
OUTPUT : 40 40

Click to Join Our Telegram Group for Latest Update of MOCK TEST

Click Here to Practice ALL Previous MOCK TEST FREE

Use Comment Box for your doubts or post similar trickey Questions
There are 10 questions to complete.

5 thoughts on “Array and Pointer C Programming Mock Test – 5”

  1. Question 7.
    Explanation doubt in last but line.

    p=p+3; //last update of variable p e.i base address is 1002+3*sizeof(char) e.i 1005.
    printf(“%d”,p+2); //does not update p, I guess.

    so, printf(“%c”,p[-3]) will be the base address 1005-3*sizeof(char)=1002. So *(1002) gives “a”.

    Reply

Leave a Comment

Like this FREE website? Please share it among all your friends and join the campaign of FREE Education to ALL.