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;
}
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.
Chandru said:
1 decade ago
Friends, please copy the program and compile with c compiler. It can compile and execute it. The output is garbage value. The answer is wrong.
Siva said:
1 decade ago
1 #include<stdio.h>
2 int main()
3 {
4 int b=0x50,a=0x10203040,c=0x60;
5 void *p=&a,**q;
6 p++;
7 printf("%x\n",*(int *)p);
8 }
Hi friends check this program output in gcc.
It won't get any error and output should be 50102030 or 60102030 based on allocation.
2 int main()
3 {
4 int b=0x50,a=0x10203040,c=0x60;
5 void *p=&a,**q;
6 p++;
7 printf("%x\n",*(int *)p);
8 }
Hi friends check this program output in gcc.
It won't get any error and output should be 50102030 or 60102030 based on allocation.
Karthik said:
10 years ago
@Siva.
What is the output got in above program?
What is the output got in above program?
Devendra said:
9 years ago
Actually, there is confusion with compiler. If you execute it in Turbo C it won't allow arithmetic on VOID* but in GCC it works fine and prints two addresses.
Pranali said:
8 years ago
@Manoj.
There is no size for void datatype.
Still if we find sizeof(void) it will give 1 byte.(minimum size have to give).
There is no size for void datatype.
Still if we find sizeof(void) it will give 1 byte.(minimum size have to give).
Ashish Jha said:
8 years ago
I compiled in gcc. It is getting compiled. I am getting the following output:
6356744 6356741
6356744 6356741
Guilloip said:
4 years ago
That is not true.
A void pointer is treated as a byte pointer.
A void pointer is treated as a byte pointer.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers