what is the purpose of these??

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jhozel
    New Member
    • Feb 2007
    • 2

    what is the purpose of these??

    { }
    ( )
    [ ]

    those are parts in making a c++ program..
    but what is the purpose or meaning of those parts??
  • horace1
    Recognized Expert Top Contributor
    • Nov 2006
    • 1510

    #2
    Originally posted by jhozel
    { }
    ( )
    [ ]

    those are parts in making a c++ program..
    but what is the purpose or meaning of those parts??
    you not only need to know what they mean but also to understand where they are used, have a read thru the C++ tutorial
    http://www.cplusplus.c om/doc/tutorial/

    Comment

    • rajesh6695
      New Member
      • Oct 2006
      • 96

      #3
      {} is used for two purpose one is to initialise multi dimesinal array and another place is to define the body of the function...

      ( ) is used while calculation similar to mathematics.... some times it may used in the specify the subset of the array but that is not a common.....

      [] is used for denoting the subset of the array...


      Better read tutorial link provided by the Horac1 to know more and clearly....

      Comment

      • DeMan
        Top Contributor
        • Nov 2006
        • 1799

        #4
        Expanding a little furhter on the answer....
        Originally posted by rajesh6695
        {} is used for two purpose one is to initialise multi dimesinal array and another place is to define the body of the function
        {} are used not just to define the body of a function, but more generically to execute a block of statements. Most commonly this is if you want a conditional statement or loop to execute more than one statement, you put these parentheses around all the code you want executed in that condition.
        eg:
        Code:
        if(something)
        {
           printf("somethind is true");
           doSomethingElse();
        }
        Without the parentheses, the program would execute the printf if something is true and the doSomethingElse method irrespective of the value of something. (I'm starting to think something is a bad variable name)


        Originally posted by rajesh6695
        ( ) is used while calculation similar to mathematics.... some times it may used in the specify the subset of the array but that is not a common
        () is used to explicitly show order of computation. This is for logical and computational values. () are also required to define parameter lists for functions (and must still be included is there are no parameters), and are required as part of the syntax of some statements.
        It is always better to include too many rather than too few of these (assuming they're in the right place, because their placement can affect the result of an expression). Consider what the boolean logic below does and when it returns true
        Code:
        boolean this, that, what
        if(this && that || what == true)  i
        
        //is this the same
        if((this && that) || what)  
        /* Requires that either both this AND that are true OR at least what is true */
        
        // or maybe
        if((this && (that || what))
        /* require that this is true AND either that or what is true*/

        Comment

        Working...