Exercise: Pointers

Questions for: Pointers

Are the three declarations char **apple, char *apple[], and char apple[][] same?
A:
True
B:
False
C:
D:
Answer: B
No answer description is available. Let's discuss.
The following program reports an error on compilation.
#include<stdio.h>
int main()
{
    float i=10, *j;
    void *k;
    k=&i;
    j=k;
    printf("%f\n", *j);
    return 0;
}
A:
True
B:
False
C:
D:
Answer: B
This program will NOT report any error. (Tested in Turbo C under DOS and GCC under Linux)

The output: 10.000000
Will the program compile?
#include<stdio.h>
int main()
{
    char str[5] = "ExamAdept";
    return 0;
}
A:
True
B:
False
C:
D:
Answer: A

C doesn't do array bounds checking at compile time, hence this compiles.

But, the modern compilers like Turbo C++ detects this as 'Error: Too many initializers'.

GCC would give you a warning.

Are the expression *ptr++ and ++*ptr are same?
A:
True
B:
False
C:
D:
Answer: B
*ptr++ increments the pointer and not the value, whereas the ++*ptr increments the value being pointed by ptr
In the following program add a statement in the function fact() such that the factorial gets stored in j.
#include<stdio.h>
void fact(int*);

int main()
{
    int i=5;
    fact(&i);
    printf("%d\n", i);
    return 0;
}
void fact(int *j)
{
    static int s=1;
    if(*j!=0)
    {
        s = s**j;
        *j = *j-1;
        fact(j);
        /* Add a statement here */
    }
}
A:
j=s;
B:
*j=s;
C:
*j=&s;
D:
&j=s;
Answer: B
No answer description is available. Let's discuss.
Ad Slot (Above Pagination)
Quiz