Array and Pointer C Programming Mock Test – 1


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


There are 5 questions to complete.

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

  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