Thread: Few noobie questions.

  1. #1
    60% Braindead
    Join Date
    Dec 2005
    Posts
    379

    Few noobie questions.

    Well, I looked through a few books, but I'm still missing a few pritty simple things. These are some pritty basic questions that probably have been asked a few times. (Hopefully basic anyways)

    First off when you say (!callfunction()) what does the ! do? Is that like: (callfunction()=0)?

    How much can a byte/SHORT/int/LONG integer hold (value-wise)?

    How do you tell the size of an array? (IE if I had an array with X values, how do I find X?)

    Is a 3D array a valid declaration? (IE I[1][20][10]; )

    Is it possible to tell where the ConsoleCursor is currently?

    If a pointer points to a 0x(0000^8) adress and you keep adding one to the pointer, will it cycle through every value on your computer?

    Can you dynamicaly expand an array? (IE: Add an extra value to an array, so from I[10] to I[11]?)

    Thank you.
    Code:
    Error W8057 C:\\Life.cpp: Invalid number of arguments in function run(Brain *)

  2. #2
    Rabble Rouser Slacker's Avatar
    Join Date
    Dec 2005
    Posts
    116
    >First off when you say (!callfunction()) what does the ! do? Is that like: (callfunction()=0)?
    "if ( !something )" is identical to "if ( something == 0 )".

    >How much can a byte/SHORT/int/LONG integer hold (value-wise)?
    byte isn't a type in C++. You can assume the following ranges:

    char: -127 to 127
    short: -32767 to 32767
    int: -32767 to 32767
    long: -2147483647 to 2147483647

    >How do you tell the size of an array?
    Divide the size of the array--the total size in bytes--by the size of any element of the array:
    Code:
    sizeof array / sizeof array[0]
    >Is a 3D array a valid declaration? (IE I[1][20][10]; )
    Yes, though an array of size 1 is kind of useless.

    >Is it possible to tell where the ConsoleCursor is currently?
    Possible yes, not portable, so it depends on your system and/or compiler.
    If a pointer points to a 0x(0000^8) adress and you keep adding one to the pointer, will it cycle through every value on your computer?
    Uh, in theory yes. In practice, don't count on it.

    >Can you dynamicaly expand an array?
    No, the size of an array is constant and doesn't change. You can simulate a dynamic array with pointers and dynamic memory though.

  3. #3
    60% Braindead
    Join Date
    Dec 2005
    Posts
    379
    Byte isint a type in C++? Then why is this a valid declaration??
    Code:
    byte enemies;
    I'm confused .

    Umm for the array part you said get the amount in the total size of bytes and devide by any part of the array, but what if all the parts of the array are 0? Or, is 0/0 a valid devision process?




    Well, thank you very much for your help, it'll... help alot .
    Code:
    Error W8057 C:\\Life.cpp: Invalid number of arguments in function run(Brain *)

  4. #4
    Unregistered User
    Join Date
    Sep 2005
    Location
    Antarctica
    Posts
    341
    because you can create an alias for another type.. say...

    Code:
    typedef unsigned char byte;
    typedef int INTEGER;
    typedef char *String;
    Now you can declare variables as:

    Code:
    byte b = 1;
    INTEGER n = 20;
    String s = "Blah";
    -- Rocky
    -- DreamSys Software (http://www.dreamsyssoft.com)
    -- Free Tiff 2 PDF Library (http://www.dreamsyssoft.com/tiff-to-pdf-api)

  5. #5
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,005
    Quote Originally Posted by Blackroot
    How much can a byte/SHORT/int/LONG integer hold (value-wise)?
    Exactly CHAR_MIN to CHAR_MAX, or UCHAR_MAX; SHRT_MIN to SHRT_MAX, or USHRT_MAX, INT_MIN to INT_MAX, or UINT_MAX; or LONG_MIN to LONG_MAX, or ULONG_MAX. #include <limits.h> [edit]Or #include <climits> (too used to the other board)

    Quote Originally Posted by Blackroot
    How do you tell the size of an array? (IE if I had an array with X values, how do I find X?)
    As stated above, but only when the array name is in scope. If you pass an array to a function, you are only passing a pointer to the first element and such information is lost.
    Last edited by Dave_Sinkula; 01-07-2006 at 11:24 PM.
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  6. #6
    Absent Minded Programmer
    Join Date
    May 2005
    Posts
    968
    For dynamic containers, like an array that can be resized and played with freely..

    Check out the STL, vectors are a good way to go for dynamic arrays.
    Sometimes I forget what I am doing when I enter a room, actually, quite often.

  7. #7
    Registered User
    Join Date
    Aug 2005
    Posts
    113
    Code:
    Is it possible to tell where the ConsoleCursor is currently?
    Compilers supporting conio.h(Borland specially) have function wherex() and wherey() which tells you position of your console cursor

  8. #8
    Rabble Rouser Slacker's Avatar
    Join Date
    Dec 2005
    Posts
    116
    >Byte isint a type in C++? Then why is this a valid declaration??
    Probably because your compiler decided to add it as an extension. Use it at your own risk though, because the code probably won't compile elsewhere.

    >but what if all the parts of the array are 0? Or, is 0/0 a valid devision process?
    0/0 isn't valid, but sizeof is guaranteed to never evaluate to 0.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. A very long list of questions... maybe to long...
    By Ravens'sWrath in forum C Programming
    Replies: 16
    Last Post: 05-16-2007, 05:36 AM
  2. noobie binary questions
    By the bassinvader in forum C Programming
    Replies: 1
    Last Post: 10-31-2006, 05:41 PM
  3. putting text onto the next line...lol...noobie questions
    By JOlszewski in forum C Programming
    Replies: 2
    Last Post: 01-24-2006, 04:02 PM
  4. Several Questions, main one is about protected memory
    By Tron 9000 in forum C Programming
    Replies: 3
    Last Post: 06-02-2005, 07:42 AM
  5. Trivial questions - what to do?
    By Aerie in forum A Brief History of Cprogramming.com
    Replies: 23
    Last Post: 12-26-2004, 09:44 AM