Thread: Structs

  1. #1
    Banned
    Join Date
    Apr 2015
    Posts
    596

    Structs

    Hey, I have studied the subject of structs.
    when I make a struct it's a general abstract concept until I make a variable of concrete type of that struct then it will allocated in the memory.
    To be more explicit for me, can someone please give me an analogous of real life which is visualizing the concept of "structs" and its allocations in the memory once declaring its variables?!



    Moreover, what happened when I write the same name in two concrete structs, meaning lets assume I have defined struct called "struct BOOK" , and write like this :
    struct BOOK b1 = {something};
    struct BOOK b1= {something different} ; so the computer will allocate for me b1 and put it's value as {something} and after being called once again struct BOOK b1={something different} ; he will go to the name b1 that's already defined previously, and put the updated value or .. ? or totally he's not allowing similarity in names(same names)?!

    thanks in advance !
    Last edited by RyanC; 12-10-2018 at 06:14 AM.

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    1. Blueprint.

    2. That's a stupid question. You should have written a program to find out for yourself. If after you observed the result of compiling that program, you wanted to check that your conclusion was correct, then that would be a smart question.
    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
    Banned
    Join Date
    Apr 2015
    Posts
    596
    Quote Originally Posted by laserlight View Post
    1. Blueprint.

    2. That's a stupid question. You should have written a program to find out for yourself. If after you observed the result of compiling that program, you wanted to check that your conclusion was correct, then that would be a smart question.
    for 1. , What do you mean exactly? I'm not meaning what the mean of "blueprint"

    for 2. , I have write what I wrote and compiler threw error of a duplicate variables ..

  4. #4
    Registered User
    Join Date
    Dec 2017
    Posts
    1,628
    1. You know what a blueprint is but you can't see the obvious analogy? A struct is to a variable as a blueprint is to a house. A blueprint/struct tells you how to make a house/variable. From one blueprint/struct can be made many houses/variables. (BTW, only retards ask for analogies.)

    2. You have 436 posts and you still don't know that you can't have two variables with the same name in the same scope? Are you capable of learning anything? At all? Ever? Stop trolling. Post complete programs. Prove you are not a retard.
    A little inaccuracy saves tons of explanation. - H.H. Munro

  5. #5
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    And you apparently already knew what a struct is for. You didn't need an analogy in the first place, which is why I decided a one-word answer was generous.

    What did you expect as a reply for #2 anyway? Didn't the compiler answer your question?
    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

  6. #6
    Registered User Kernelpanic's Avatar
    Join Date
    Sep 2018
    Location
    Berlin
    Posts
    105
    Quote Originally Posted by laserlight View Post
    And you apparently already knew what a struct is for. You didn't need an analogy in the first place, which is why I decided a one-word answer was generous.

    What did you expect as a reply for #2 anyway? Didn't the compiler answer your question?
    He is a case for Sigmund Freud - really.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 01-08-2013, 07:55 AM
  2. Typedef Structs inside Typdef structs
    By gremory in forum C Programming
    Replies: 21
    Last Post: 12-30-2011, 07:48 PM
  3. [ noob question ] Help with structs within structs
    By Riverfoot in forum C Programming
    Replies: 3
    Last Post: 04-26-2011, 07:24 PM
  4. Passing Structs Into An Array Of Structs.
    By TheTaoOfBill in forum C Programming
    Replies: 3
    Last Post: 10-07-2010, 09:38 AM
  5. passing structs & pointers to structs as arguments
    By Markallen85 in forum C Programming
    Replies: 6
    Last Post: 03-16-2004, 07:14 PM

Tags for this Thread