Thread: Declaring Varibles

  1. #1
    Registered User
    Join Date
    Feb 2003
    Posts
    1

    Red face Declaring Varibles

    I'm just learning C++ in a class I'm taking in college, but I have had Java. How do I declare varibles Such as (float, integer, double, char and Bol.??



    Please help!!

    Thanks

  2. #2
    Registered User
    Join Date
    Sep 2002
    Posts
    1,640
    Like so

    Code:
     int a=3;
     float length=0.34;

  3. #3
    Registered User
    Join Date
    Oct 2002
    Posts
    291
    thought it was the same as java.

    Code:
      float number = 12.34f;
      double number2 = 12.3456;
      int number3 = 12;
      char name[] = "Hello";
      bool loop(true);

  4. #4
    Registered User
    Join Date
    Sep 2002
    Posts
    1,640
    Originally posted by laasunde
    Code:
      bool loop(true);
    Never seen a bool declared like that ever.
    Just to be sure use this.

    Code:
     bool loop=true;

  5. #5
    Registered User
    Join Date
    Dec 2001
    Posts
    479

    I'm just learning C++ in a class I'm taking in college, but I have had Java. How do I declare varibles Such as (float, integer, double, char and Bol.??
    these things should be included in the first lesson!
    please leave the name of the college and the name of your teacher so others dont make the same misstake!

  6. #6
    Registered User Cela's Avatar
    Join Date
    Jan 2003
    Posts
    362
    >>Never seen a bool declared like that ever.
    All types have a constructor, even built in types. So you can use the initialization value as a constructor argument:
    Code:
    int a(10);
    bool loop(true);
    and the functionality is equivalent to
    Code:
    int a = 10;
    bool loop = true;
    :-)
    *Cela*

  7. #7
    Registered User
    Join Date
    Oct 2002
    Posts
    291
    Originally posted by Travis Dane
    Never seen a bool declared like that ever.
    Just to be sure use this.

    Code:
     bool loop=true;
    You can declare a string two ways :
    Code:
      string name = "john";
      string name2("john");
    by the same token I thought you could declare bool :
    Code:
      bool x=true;
      bool y(true);
    Works fine on my computer anyway

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. problems storing values in varibles
    By stodd04 in forum C Programming
    Replies: 7
    Last Post: 02-08-2005, 11:56 AM
  2. different ways of declaring classes
    By confuted in forum C++ Programming
    Replies: 7
    Last Post: 08-19-2003, 08:35 AM
  3. declaring a large array problem !
    By Array_Troubled in forum C++ Programming
    Replies: 10
    Last Post: 01-08-2003, 06:02 AM
  4. Declaring Pointers/Passing Data
    By Ryan_P in forum C++ Programming
    Replies: 10
    Last Post: 12-18-2002, 02:49 PM
  5. Declaring Functions
    By Thantos in forum C Programming
    Replies: 3
    Last Post: 09-25-2001, 10:24 PM