Thread: doubt in boolean and array

  1. #1
    Registered User
    Join Date
    Oct 2012
    Posts
    33

    doubt in boolean and array

    im trying to convert VB code to c programming
    In the main function it declared as
    bool res;
    and then they equate it to function
    res = array(array 1 ,array2);
    is it possible to equate like this

  2. #2
    SAMARAS std10093's Avatar
    Join Date
    Jan 2011
    Location
    Nice, France
    Posts
    2,694
    I do not think C supports boolean types as primitive type.You have to replace it with an int which will have values 0 and 1

  3. #3
    Registered User
    Join Date
    May 2012
    Posts
    1,066
    Since C99 there is a boolean type in stdbool.h.

    Bye, Andreas

  4. #4
    Registered User
    Join Date
    Oct 2012
    Posts
    33
    Or is it possible to write the array function as
    bool array(array1[],array2[])
    res = array(array1,array2);

  5. #5
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Yes, it is. AndiPersti already gave you a pointer in that direction.
    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
    SAMARAS std10093's Avatar
    Join Date
    Jan 2011
    Location
    Nice, France
    Posts
    2,694
    Quote Originally Posted by AndiPersti View Post
    Since C99 there is a boolean type in stdbool.h.

    Bye, Andreas
    Thank you Andreas.I wasn't aware of that.If someone -for some reason- does not want to use this library then we can construct by his own.
    Quote Originally Posted by prathiksa View Post
    Or is it possible to write the array function as
    bool array(array1[],array2[])
    res = array(array1,array2);
    It is possible to have the prototype as
    Code:
    bool array(array1[],array2[]);
    and inside the body of the function to return true,false or a variable which is declared as bool
    (assuming you use the library that Andreas suggested)

  7. #7
    Registered User
    Join Date
    Oct 2012
    Posts
    33
    Thanks

  8. #8
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Well, the prototype should actually be:
    Code:
    bool array(T1 array1[], T2 array2[]);
    where T1 and T2 are the types of the elements of the respective arrays. You may also need a size parameter for each array since you will only be passing a pointer.
    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

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. most efficient way of displaying a *HUGE* boolean array
    By manasij7479 in forum C++ Programming
    Replies: 9
    Last Post: 05-13-2011, 12:05 PM
  2. a Movement doubt in an array
    By louis_mine in forum C Programming
    Replies: 4
    Last Post: 02-03-2005, 09:12 PM
  3. Replies: 4
    Last Post: 04-02-2004, 07:30 PM
  4. Boolean in a character array
    By newy100 in forum C++ Programming
    Replies: 7
    Last Post: 11-29-2003, 01:32 PM
  5. Array of boolean
    By DMaxJ in forum C++ Programming
    Replies: 11
    Last Post: 10-25-2001, 11:45 PM

Tags for this Thread