By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,897 Members | 1,955 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,897 IT Pros & Developers. It's quick & easy.

what is the purpose of these??

P: 2
{ }
( )
[ ]

those are parts in making a c++ program..
but what is the purpose or meaning of those parts??
Feb 21 '07 #1
Share this Question
Share on Google+
3 Replies


Expert 100+
P: 1,510
{ }
( )
[ ]

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.com/doc/tutorial/
Feb 21 '07 #2

P: 96
{} 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....
Feb 21 '07 #3

DeMan
100+
P: 1,806
Expanding a little furhter on the answer....
{} 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:
Expand|Select|Wrap|Line Numbers
  1. if(something)
  2. {
  3.    printf("somethind is true");
  4.    doSomethingElse();
  5. }
  6.  
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)


( ) 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
Expand|Select|Wrap|Line Numbers
  1. boolean this, that, what
  2. if(this && that || what == true)  i
  3.  
  4. //is this the same
  5. if((this && that) || what)  
  6. /* Requires that either both this AND that are true OR at least what is true */
  7.  
  8. // or maybe
  9. if((this && (that || what))
  10. /* require that this is true AND either that or what is true*/
  11.  
  12.  
Feb 21 '07 #4

Post your reply

Sign in to post your reply or Sign up for a free account.