Thread: giving value to structure elements

  1. #1
    Registered User
    Join Date
    Feb 2008
    Posts
    39

    giving value to structure elements

    if i am having a following structure

    Code:
    struct emp
    {
         int acc;
         char name;
    };
    struct emp e;
    if i am giving value as

    Code:
    e.acc|=ACC_NO;
    what the above statement mean. can anyone explain me...

    thanks in advance...

  2. #2
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Quote Originally Posted by sarathius View Post
    if i am having a following structure

    Code:
    struct emp    //a struct is defined
    {
         int acc;     //with these parts
         char name;     
    };
    struct emp e;  //a struct of type emp is created, and named e
    if i am giving value as

    Code:
    e.acc|=ACC_NO;   //mistype, correct is e.acc = variable, not e.acc |= variable
    what the above statement mean. can anyone explain me...
    The last line of code shows the dot operator, which is used to access the parts of the struct. Note that "char name" is not an array of char's, but only a single char. To make it longer, you need to make it a char array - char name[40], for example.

    Remember that a bunch of char's is not a string, in C. No matter how many there are of them. They are elevated to a string ONLY when they have an End of String marker char, placed as their last value: '\0'.

    So: "Frederick" is not a string, but "Frederick\0" is one.

  3. #3
    Registered User
    Join Date
    Feb 2008
    Posts
    39
    ya, you are right. But, i need help for the second statement in assigning values for structure elements. what's that "or(|)" symbol comes here.

  4. #4
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    It's used to set specific bits in a variable. Typically used to combine several flags into one variable.
    One flag sets bit 1, the next bit 2, and so on.

    See it as
    SetBit(e.acc, ACC_NO);
    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. Passing Structure Pointers to Functions
    By samus250 in forum C Programming
    Replies: 15
    Last Post: 03-20-2008, 03:13 PM
  2. Replies: 13
    Last Post: 12-14-2007, 03:34 PM
  3. passing structure arrays to functions?
    By bem82 in forum C Programming
    Replies: 3
    Last Post: 10-30-2006, 06:17 AM
  4. 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
  5. referencing C structure elements in assembly
    By BigAl in forum C Programming
    Replies: 7
    Last Post: 09-10-2001, 03:19 PM