C Programming - Declarations and Initializations - Discussion

Discussion Forum : Declarations and Initializations - Point Out Errors (Q.No. 2)
2.
Point out the error in the following program.
#include<stdio.h>
int main()
{
    void v = 0;

    printf("%d", v);

    return 0;
}
Error: Declaration syntax error 'v' (or) Size of v is unknown or zero.
Program terminates abnormally.
No error.
None of these.
Answer: Option
Explanation:
No answer description is available. Let's discuss.
Discussion:
165 comments Page 7 of 17.

Devi said:   1 decade ago
Void is a data type and we can use it at any time.

BaBa said:   1 decade ago
Only function and pointer can be declare as void not variable.

119 said:   1 decade ago
Void is special kind of data type which is only built for functions return type (where no value is returned). So we cannot use this for any kind of variable declaration.

HEMALATHA said:   1 decade ago
What is the format specifier for 'void'?

Mohini said:   1 decade ago
Void is a primitive data type but it declaration of variable using void is wrong!thats it.

K SURESHBABU said:   1 decade ago
void means that it does not return nothing.Here void declare to the V is not taken.

Prathyu said:   1 decade ago
We couldn't use &v in printf. We use that symbol for taking input from user in scanf statement not in printf statement.

Babulu said:   1 decade ago
void is a data type it can holds any type of data(int,float,char..)so, if u want to print void type of data need to type cast in to that stream .
printf("%d", v);

In this statement %d(int type)
So need to typecast in to integer like
printf("%d",(int)v);

Gourab Paul said:   1 decade ago
The void type is said to comprise an empty set of values, and the C language does not provide any way to declare an object or represent a value with type void.
Thats why for the above problem the compiler shows the following:
Error: Declaration syntax error 'v' (or) Size of v is unknown or zero.

#include<stdio.h>
int main()
{
void v = 0;
/*C language does not provide any way to
declare an object or represent a value with type void*/

printf("%d", v);

return 0;
}

Suprava mallick said:   1 decade ago
void can't be a data type, It is a return type which return null so it can't be declare with a variable name.

Ex: void a;// It show u an error.

Pointer variable declared as void. So it gives an error


Post your comments here:

Your comments will be displayed after verification.