One more question on struct and pointer...

This is a discussion on One more question on struct and pointer... within the C Programming forums, part of the General Programming Boards category; Hai friends one more question on struct Code: #include<stdio.h> struct node { int i; int *j; }; main() { struct ...

  1. #1
    Registered User
    Join Date
    Oct 2007
    Posts
    54

    One more question on struct and pointer...

    Hai friends one more question on struct
    Code:
    #include<stdio.h>
    struct node
    {
    int i;
    int *j;
    };
    main()
    {
    struct node *ptr;
    ptr->i=10;
    ptr->(*j)=20;/*i am thinking that it is not possible can any one tell me that how to do this*/
    }
    now i am not having compiler so i am asking to you members so please tell me how to access that pointer in the structure
    Last edited by sreeramu; 12-06-2007 at 06:40 AM.

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,434
    Assuming it is allocated some space, then it's
    *struct->j

    Oh, and you really need to get a compiler ASAP.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Registered User
    Join Date
    Oct 2007
    Posts
    54
    Now i am using mobile browser so please any one and help me to understand it...

  4. #4
    Registered User
    Join Date
    Oct 2007
    Posts
    54
    Thank you salem ...So now if i want to access the pointer variable in the structure means i want to use this
    Code:
    *ptr->j=20;
    am i correct...
    Last edited by sreeramu; 12-06-2007 at 06:41 AM.

  5. #5
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,422
    Quote Originally Posted by Salem View Post
    Assuming it is allocated some space, then it's
    *struct->j

    Oh, and you really need to get a compiler ASAP.
    I think you mean struct->j or (*struct).j.
    This isn't a struct** after all.

    Quote Originally Posted by sreeramu View Post
    Thank you salem ...So now if i want to access the pointer variable in the structure means i want to use this
    Code:
    *ptr->j=20;
    am i correct...
    No, it's ptr->j or (*ptr).j.
    Your main delcaration is incorrect too, see signature.
    And you haven't allocated any memory for your pointer in the sample either, so you will get an access violation when you run that code.
    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. memory issue
    By t014y in forum C Programming
    Replies: 2
    Last Post: 02-20-2009, 11:37 PM
  2. Binary Search Trees Part III
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 03:00 PM
  3. towers of hanoi problem
    By aik_21 in forum C Programming
    Replies: 1
    Last Post: 10-02-2004, 01:34 PM
  4. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 09:33 AM
  5. Contest Results - May 27, 2002
    By ygfperson in forum A Brief History of Cprogramming.com
    Replies: 18
    Last Post: 06-18-2002, 01:27 PM

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