C Programming - Declarations and Initializations - Discussion

Discussion Forum : Declarations and Initializations - Point Out Errors (Q.No. 3)
3.
Point out the error in the following program.
#include<stdio.h>
struct emp
{
    char name[20];
    int age;
};
int main()
{
    emp int xx;
    int a;
    printf("%d\n", &a);
    return 0;
}
Error: in printf
Error: in emp int xx;
No error.
None of these.
Answer: Option
Explanation:

There is an error in the line emp int xx;

To overcome this error, remove the int and add the struct at the begining of emp int xx;

#include<stdio.h>
struct emp
{
    char name[20];
    int age;
};
int main()
{
    struct emp xx;
    int a;
    printf("%d\n", &a);
    return 0;
}
Discussion:
30 comments Page 2 of 3.

K.R.Shivraj said:   9 years ago
Yes, we can use & in printf statement refer tutorials point for your better clearance.

Ravi said:   1 decade ago
Here & in printf is absolutely correct as it is going to print the address of a.

Sesi Praveen said:   10 years ago
a is not defined. How can it print the value of a? It is an error, somebody reply.

Mithilesh Upadhyay said:   1 decade ago
I think the address operator '&' should not be in the Printf() statement.

Vaibhav said:   7 years ago
How can I identify?

That,
emp int xx; is an error can anyone help me?

Kausar Barkat said:   1 decade ago
What about the & sign in printf statement? Isn't that an error?

Ashu said:   1 decade ago
& operator we can not used in printf it should be in scanf.

Kajal said:   6 years ago
As per my knowledge, We can't use & in printf statement.
(3)

Rohit said:   1 decade ago
In case of printf statmnt.

Can we write ampersand sign not?

Jaiyant Prasad said:   8 years ago
We can't use & in print.

So option A is also correct.


Post your comments here:

Your comments will be displayed after verification.