Solved

c question

Posted on 2007-03-26
2
196 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
Comment Utility
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
Comment Utility
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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Preface I don't like visual development tools that are supposed to write a program for me. Even if it is Xcode and I can use Interface Builder. Yes, it is a perfect tool and has helped me a lot, mainly, in the beginning, when my programs were small…
This tutorial is posted by Aaron Wojnowski, administrator at SDKExpert.net.  To view more iPhone tutorials, visit www.sdkexpert.net. This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
The goal of this video is to provide viewers with basic examples to understand recursion in the C programming language.
The goal of this video is to provide viewers with basic examples to understand opening and reading files in the C programming language.

728 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now