Thread: One more question on struct and pointer...

  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 07:40 AM.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    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.

  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 07:41 AM.

  5. #5
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    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-21-2009, 12:37 AM
  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, 10: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