Thread: What is type struct

  1. #1
    Registered User
    Join Date
    Nov 2019
    Posts
    66

    What is type struct

    What is type struct ?

    Type variable // we change the type


    Code:
    type integer    int x     // x store integer value x = 12
    
    type charactr  char y   // y store charactr value y = 'K'
    
    type float       float z    // z store floating value z = 11.09
    type struct ?
    Last edited by Player777; 02-09-2020 at 11:36 PM.

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    27,778
    A struct type is a type that can be used to group objects of various types together into a single object.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Nov 2019
    Posts
    66
    Quote Originally Posted by laserlight View Post
    A struct type is a type that can be used to group objects of various types together into a single object.
    I did not understand the meaning of your definition. It would be better to prove your definition by example

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    27,778
    You can find such examples in any good introductory C textbook.

    Nonetheless, here is an example:
    Code:
    struct X
    {
        int a;
        float b;
    };
    Then using the notation you used in post #1:
    Code:
    type struct X       struct X w    // w store integer value w.a = 12 and floating value w.b = 11.09
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  5. #5
    Registered User
    Join Date
    Nov 2019
    Posts
    66
    Quote Originally Posted by laserlight View Post
    You can find such examples in any good introductory C textbook.
    point type integer int *a
    point type charactr char *b
    pointer type float float *c

    What is pointer type struct

    struct X * v;

    Does the pointer point to the structure object v


    Does the pointer point to the structure name X

  6. #6
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    27,778
    Quote Originally Posted by Player777
    Does the pointer point to the structure object v
    The pointer is named v.

    Quote Originally Posted by Player777
    Does the pointer point to the structure name X
    C programmers often loosely use the word "struct" or "structure" to mean an object of struct type. In your example, there is no such object. struct X refers to the type, not the object.

    What material are you using to learn C?
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  7. #7
    Registered User
    Join Date
    Nov 2019
    Posts
    66
    Quote Originally Posted by laserlight View Post
    The pointer is named v.


    C programmers often loosely use the word "struct" or "structure" to mean an object of struct type. In your example, there is no such object. struct X refers to the type, not the object.

    What material are you using to learn C?
    k&r c programming

    Code:
    struct X{
       int a;
       int b;
    }
    
    
    int main ()
    {
       struct X * v;
    
    
        v->a ; v is pointer and a is structure object
        v->b ; v is pointer and b is structure object
        
        return 0;
    }
    What does struct type store ?

  8. #8
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    27,778
    Quote Originally Posted by Player777
    k&r c programming
    If you're having difficulty understanding K&R, then put it aside for now and reach for a beginner's introductory book rather than an experienced programmer's introductory book.

    Quote Originally Posted by Player777
    Code:
    v->a ; v is pointer and a is structure object
    v->b ; v is pointer and b is structure object
    What does the term "structure object" mean to you?
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  9. #9
    Registered User
    Join Date
    Nov 2019
    Posts
    66
    Quote Originally Posted by laserlight View Post
    What does the term "structure object" mean to you?
    Structure is a group of different data types and each element in a C structure is called member

    type int store integer value x = 12
    type char store charactr value y = 'K'
    type float store floating value z = 11.09

    What does type struct store ?

  10. #10
    misoturbutc Hodor's Avatar
    Join Date
    Nov 2013
    Posts
    1,750
    Quote Originally Posted by Player777 View Post
    Structure is a group of different data types and each element in a C structure is called member

    type int store integer value x = 12
    type char store charactr value y = 'K'
    type float store floating value z = 11.09

    What does type struct store ?
    It stores an aggregate of types

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Cannot convert parameter to struct type.
    By Liangine in forum C++ Programming
    Replies: 7
    Last Post: 11-03-2013, 11:24 PM
  2. invalid use of incomplete type 'struct a'
    By ajoqiqu in forum C++ Programming
    Replies: 19
    Last Post: 05-16-2010, 11:59 AM
  3. Use struct to create a boolean type
    By skyglin in forum C Programming
    Replies: 6
    Last Post: 06-18-2003, 08:21 PM
  4. Struct storage with char* type ?
    By GrandmaMike in forum C Programming
    Replies: 2
    Last Post: 04-26-2002, 01:42 PM
  5. return type: struct
    By lliero in forum C Programming
    Replies: 2
    Last Post: 04-16-2002, 04:09 PM

Tags for this Thread