structure variables

This is a discussion on structure variables within the C Programming forums, part of the General Programming Boards category; I want to know what will be the output for the following statement. whether it is correct or not. If ...

  1. #1
    Registered User
    Join Date
    Feb 2008
    Posts
    39

    structure variables

    I want to know what will be the output for the following statement. whether it is correct or not. If it is wrong what would be the correct code.

    Code:
    struct name *h={10,"aa"};

  2. #2
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,484
    what would be the correct code.
    It depends on what you want to get. There are a lot of correct codes there. You do not expect me to write all the infinite possibilities here?
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  3. #3
    Registered User
    Join Date
    Feb 2008
    Posts
    39
    tell me any one possibility to give a values for structure pointer.

  4. #4
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,484
    struct name *h = NULL;
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  5. #5
    Registered User
    Join Date
    Feb 2008
    Posts
    39
    i dont want to give null value. i need to give some values.

    for eg:-
    Code:
    struct name
    {
       char nam[10];
    };
    
    struct acc
    {
       int accno;
       struct name *n;
    };
    
    void acc(struct acc *f)
    {
      struct acc *f={11,"aa");
    }
    
    void disp(struct acc *f)
    {
     printf("acc no=%d",f->accno);
     printf("name=%s",f->n->nam);
    }
    can i give like this.

  6. #6
    Day Dreamer
    Join Date
    Apr 2007
    Posts
    45
    Quote Originally Posted by sarathius View Post
    Code:
    void acc(struct acc *f)
    {
      struct acc *f={11,"aa");  
    }
    can i give like this.
    Of course you CANT!
    You have not allocated any space for the pointer f!!!
    I would love to change the world but they dont give me the source code!

  7. #7
    Registered User
    Join Date
    Feb 2008
    Posts
    39
    then how could i give values

  8. #8
    Woof, woof! zacs7's Avatar
    Join Date
    Mar 2007
    Location
    Australia
    Posts
    3,459
    Learn C perhaps?

  9. #9
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,604
    Here's some good material for pointers, at least:
    http://cpwiki.sourceforge.net/A_pointer_on_pointers

    Among others.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. basic question about global variables
    By radeberger in forum C++ Programming
    Replies: 0
    Last Post: 04-06-2009, 12:54 AM
  2. Replies: 15
    Last Post: 09-30-2008, 02:12 AM
  3. esbo's data sharing example
    By esbo in forum C Programming
    Replies: 49
    Last Post: 01-08-2008, 10:07 PM
  4. passing structure arrays to functions?
    By bem82 in forum C Programming
    Replies: 3
    Last Post: 10-30-2006, 05:17 AM
  5. Another Linked List plee
    By Dragoncaster131 in forum C Programming
    Replies: 3
    Last Post: 05-15-2004, 05:40 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21