C Programming - Pointers - Discussion

Discussion Forum : Pointers - Yes / No Questions (Q.No. 4)
4.
Will the program compile in Turbo C?
#include<stdio.h>
int main()
{
    int a=10, *j;
    void *k;
    j=k=&a;
    j++;
    k++;
    printf("%u %u\n", j, k);
    return 0;
}
Yes
No
Answer: Option
Explanation:

Error in statement k++. We cannot perform arithmetic on void pointers.

The following error will be displayed while compiling above program in TurboC.

Compiling PROGRAM.C:
Error PROGRAM.C 8: Size of the type is unknown or zero.

Discussion:
17 comments Page 2 of 2.

Ashish Jha said:   8 years ago
I compiled in gcc. It is getting compiled. I am getting the following output:

6356744 6356741

Sam said:   1 decade ago
It will be compiled. As it should display the memory locations next to the location of a.

Megala said:   1 decade ago
I think the statement
j=k=&a;
is wrong

It will generate compiler error.

Vishu said:   1 decade ago
There are no errors in the above program. I compiled and I got the output.

Guilloip said:   4 years ago
That is not true.

A void pointer is treated as a byte pointer.

Manish said:   1 decade ago
The void pointer can't perform arithmetic operation.

Karthik said:   10 years ago
@Siva.

What is the output got in above program?


Post your comments here:

Your comments will be displayed after verification.