Solved

c question

Posted on 2007-03-26
2
198 Views
Last Modified: 2010-04-15
what does a=(0) mean in this code.??

int main(){
    struct xyz{
           int i;
           };
        xyz *p,a=(10);
        *p=a;
        p->i=10;
        printf("%d",a.i);
        getch();
}
0
Comment
Question by:shilpi84
2 Comments
 
LVL 53

Accepted Solution

by:
Infinity08 earned 250 total points
ID: 18794598
It's not valid C.

Use this instead :

int main(){
  struct xyz {
    int i;
  };
  struct xyz *p, a = { 10 };  /* <-- the correct way to initialize a struct is with {}'s */
                              /* <-- you have to use "struct xyz" instead of just "xyz" */
  p = &a;   /*  <-- don't assign to *p, as you haven't allocated memory for it !! */
  p->i = 10;
  printf("%d", a.i);
  getch();
}
0
 
LVL 84

Assisted Solution

by:ozo
ozo earned 250 total points
ID: 18794629
assuming you meant
 struct xyz *p,a={10};
it means
struct xyz a;
a.i=10;

but
 *p=a;
refrerences an uninitialized pointer, which makes the behaviour of the program undefined
0

Featured Post

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Estimate porting issues. 9 120
How to programmatically differentiate between C and Java 10 204
valid enum? 6 75
How do I set up two external hard drives with Acronis True Image? 12 93
Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
The goal of this video is to provide viewers with basic examples to understand and use pointers in the C programming language.
The goal of this video is to provide viewers with basic examples to understand recursion in the C programming language.

789 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question