Advertise here




Advertise here

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In with Google Sign In with OpenID
Please do not post the same thing multiple times. The board software automatically flags certain posts as needing moderator attention. This happens the most often for new users. I'm pretty sure this is made clear at the time you attempt to post. Posting the same thing over and over again just makes that many more posts the moderators have to weed through later. This makes us sad. Don't make us sad. If your post/thread doesn't appear, just wait a while. Don't post it again. If it hasn't shown up by the next day, then you can try again. I normally go through posts in the mornings, and try to check a few times throughout the day, but I'm not here 24/7. There will typically be a significant delay before posts are approved. Just be patient.

Structs

MurphyMurphy Posts: 60Registered Users
{
{
struct budget{
int a;
int b;
int c; };

int someInteger;{
struct budget myBudget;
myBudget.a = 1;
myBudget.b = 100;
myBudget.c = 300;

}



When I create the int named someInteger here then open braces { and create the (variable?) myBudget wich sets the value of a,b,c in the structs. What is the relationship with the integer (someInteger) ?

since I have used { and written the variable like:

int someInteger;{ //set values of struct

there is some relationship to the int now correct?
Post edited by Murphy on

Replies

  • Duncan CDuncan C Posts: 8,015Tutorial Authors, Registered Users
    Murphy;439952 said:
    {
    {
    struct budget{
    int a;
    int b;
    int c; };

    int someInteger;{
    struct budget myBudget;
    myBudget.a = 1;
    myBudget.b = 100;
    myBudget.c = 300;

    }



    When I create the int named someInteger here then open braces { and create the (variable?) myBudget wich sets the value of a,b,c in the structs. What is the relationship with the integer (someInteger) ?

    since I have used { and written the variable like:

    int someInteger;{ //set values of struct

    there is some relationship to the int now correct?
    Dude, you are flailing around lost, misunderstanding lots of things. Get yourself a good book on C and Objective C and read it.

    Braces are used in different ways in C.

    When you declare a struct, you provide a list of the different elements of that struct enclosed in braces.

    Anywhere in the body of your code, you can also enclose a block of code in braces. That has the effect of creating a local scope. Variables declared inside braces (inside your .m file) only exist inside those braces. After the closing brace, they go out of scope and cease to exist.

    I don't think you can use braces the way you did in your example in the header (.h file.)

    In any case, using braces the way you do in your example does not create any relationship between someInteger and your budget structure.
    Regards,

    Duncan C
    WareTo

    mug

    Animated GIF created with Face Dancer, available for free in the app store.
  • MurphyMurphy Posts: 60Registered Users
    I don't think you can use braces the way you did in your example in the header (.h file.)


    The compiler didn´t give me any warning - I thought it was weird, so I started to wonder if somehow this created some connection... wish would have been weird.

    I know about using braces to declare local variables/scope. But I didnt think this coude would compile. I can even do this (one more {), and it compiles...

    I have lot´s of good books on Obj-C - but has only been learning it for about 1 month. and pre-learning this I have no programming or computer science experience so I am bound to mix up some terms.
    {
    {
    struct budget{
    int a;
    int b;
    int c; };

    {int someInteger;{
    struct budget myBudget;
    myBudget.a = 1;
    myBudget.b = 100;
    myBudget.c = 300;

    }
Sign In or Register to comment.