0 Up votes0 Down votes

5 views5 pagesCE206

Mar 21, 2013

© Attribution Non-Commercial (BY-NC)

PDF, TXT or read online from Scribd

CE206

Attribution Non-Commercial (BY-NC)

5 views

CE206

Attribution Non-Commercial (BY-NC)

- AIMP3_MemoryManager_EventLog
- c++ project on supermarket
- Railway Reservation
- Banking
- Download Computer Science Technical Aptitude Interview Questions
- 12 Java projects
- cprogramming_mock_test_i.pdf
- Arrays
- Discussion 1
- prog39-47
- Compre Closed Book
- New Text Document (6)
- IBM Sample Paper5
- Untitled 1
- MIT6_087IAP10_lec07[1]
- Networking Lab
- Cs9216 Networking Lab
- Networking Lab
- nvcc
- Pi Calculation

You are on page 1of 5

The number of bites used for some data types vary from compiler to compiler. However we can get this information by using the sizeof() operator. #include<iostream> using namespace std; void main() { // Program - P03 cout<<"Size (number of bytes) of different data types\n\n"; cout<<"Size of \'int \'= "<<sizeof(int)<<endl; cout<<"Size of \'double =\'= "<<sizeof(double)<<endl; cout<<"Size of \'short \' = "<<sizeof(short)<<endl; cout<<"Size of \'long \' = "<<sizeof(long)<<endl; cout<<"Size of \'float \' = "<<sizeof(float)<<endl; cout<<"Size of \'char \' = "<<sizeof(char)<<endl; cout<<"Size of \'long double \' = "<<sizeof(long double)<<endl; float weight=25.0; int serial_no=5; cout<<"Size of \'weight \' = "<<sizeof weight<<endl; cout<<"Size of \'serial_no \' = "<<sizeof(serial_no)<<endl; }

Note sizeof( ) is a unary operator so it takes a single operand it returns an integer value that represents the number of bytes occupied by a type or by a variable to find the size of a type you have to put the type name inside the parenthesis to find the size of a variable you may put the variable name without parenthesis you can apply sizeof operator even to an expression and the expression does not necessarily have to be within parenthesis Finding the limits We can find out the maximum value that can be stored in a variable of a given type using the expression numeric_limits<type_name>::max() To find the minimum value numeric_limits<type_name>::min() The standard header file limits is required for the above. Escape sequence We can enter control characters and certain other characters by means of escape sequence. ............................................................................. #include<iostream> using namespace std; void main() { // Test program cout<<Trial Program; } ........................................................................... When we run the above program the following appear in the output window on the monitor Trial ProgramPress any key to continue

Notice the effect of escape sequences on output of the following program Now if we modify the program as follows then ........................................................ #include<iostream> using namespace std; void main() { // Test program cout<<Trial Program\n; //this line is changed } .............................................................. Trial Program Press any key to continue //Program P05 #include<iostream> using namespace std; void main() { // Test program cout<<"Trial Program\nI wrote it\n\tIt is a simple program"; cout<<"\n\"Program showing the effect of escape sequence\"\n"; } Output of the above program is

As you can see due to the placement of \n the message from operating system is now printed on the next line. Thus we can control the appearance of string output or message by using escape sequence.

Note /n has the same effect as endl (we used it in our first program) m number of /n produce m-1 blank lines Arithmetic operators Operator Operation + Addition Subtraction * Multiplication / Division % Modulus (the remainder after division) Note: 5/2 -> 2, 5.0/2 -> 2.5, 5./2 -> 2.5, 5/2.0 -> 2.5 5%2 -> 1, 10%4 -> 2, 15%3 -> 0 For division if the two operands are integer (number or variable) then the expression returns only the integer part of the actual result. The operands of % must be integer

Escape Sequence \n \t \v \b \r \f

Control Character newline horizontal tab vertical tab backspace carriage return form feed

Escape Sequence \a \\ \ \ \?

Control Character alert-bell backslash single quote double quote question mark

precedence and associativity of arithmetic operators Suppose we have written an expression 4 * 5 / 3 % 4 +7 / 3 Which operator will be executed first? In an expression involving several different operators, the order in which the operators are executed is determined by their precedence rule. * / % are of higher precedence than + and * / % are of equal precedence + and are of equal precedence However we can overrule the above precedence by use of parenthesis. When there are consecutive operators of equal precedence (such as in the expression 4 * 10 / 6 % 4 ) then the sequence in which these will be executed is determined by their associativity. * / % are left associative and these will be executed from left to right. + and are also left associative An example to show the importance of associativity 20/4/2 ==> 5 /2 =2 However if 4/2 is evaluated first then the result would have been 20/2 =10 // Program - P07 #include<iostream> using namespace std; void main( ) { cout<<endl<<endl<<" 20/4/2 = "<<20/4/2; cout<<endl<<endl<<" (20/4)/2 = "<<(20/4)/2; cout<<endl<<endl<<" 20/(4/2) = "<<20/(4/2) <<endl; } ==> ==> ==> ==>

If the above expression were right associative then it would have been evaluated as 4 * 10 / 6 % 4 4 * (10 / (6 % 4)) 4 * (10 / 2) 4*5 20

Additional examples 10 + 20 / 10 5 ==> 10 + 2 5 ==> 12 5 ==> 7 (10 +20) / 10 5 ==> 30 / 10 5 ==> 3-5 ==> -2

However, in an expression such as 4 * 5 / 3 % 4 + 7 / 3 we cannot say whether the sub-expression 4 * 5 / 3 % 4 will be evaluated first or 7 / 3 will be evaluated first. It depends on the compiler and we dont need to know it because the result is same for both the cases.

Assignment operators ( = += -= *= /= ) // Program - P06 #include<iostream> using namespace std; void main() { cout<<endl<<" 4*10/6%4 ="<<4*10/6%4; cout<<endl<<" 4 * 10 = "<<4*10; cout<<endl<<" 40 / 6 = "<<40/6; cout<<endl<<" 6 % 4 = "<<6%4; cout<<endl<<" ((4*10)/6)%4 ="<<((4*10)/6)%4; cout<<endl<<" If * / % were right associative then" <<endl<<" the following would have occurred"; cout<<endl<<" 6 % 4 ="<<6%4; cout<<endl<<" 10 / 2 ="<<10/2; cout<<endl<<" 4 * 5 ="<<4*5; cout<<endl<<" 4*(10/(6%4)) ="<<4*(10/(6%4)) <<endl; } int age; ............ age = 25; 25 is stored in the integer memory location named age.

We cannot write statements like 25 = age; The left side of the = operator must be a single variable If we write a = 5.2; b = a + 4; //the right side is first evaluated and then the result is stored in the variable to the left Suppose you wrote int weight; ....... weight = 25.5; cout<<weight; The output will be 25 not 25.5 because weight is declared as int type

We can write statements as below : length = width = 5; apples = oranges = 50; a = b = c / 2.2; Remember the = operator is right associative. Therefore in the first one of the above examples 5 is first stored in width and then the value in width is stored in length. So it is effectively length = (width = 5); It implies that the expression width = 5 has value namely the value stored in oranges. In fact we can write statements like fruits = ( oranges = 10) + ( apples = 11) ; This will store 10 in oranges, 11 in apples, then add the two together and store the result in fruits.

Suppose part of a program code is as follows int a; ................... a = 2; ............. memory is allocated for integer variable named a 2 is stored in the memory location named a Some commonly used library functions (header file : math.h / cmath.h) Function Type Purpose abs(i) int Return the absolute value of i acos(d) double Return the arc cosine of d asin(d) double Return the arc sine of d atan(d) double Return the arc tangent of d cos(d) double Return the cosine of d sin(d) double Return the sine of d cosh(d) double Return the hyperbolic cosine of d sinh(d) double Return the hyperbolic sine of d tanh(d) double Return the hyperbolic tangent of d exp(d) log(d) log10(d) double double double Raise e to the power d (e=2.781818.. Naperian base) Return the natural logarithm (base e) of d Return the logarithm (base 10) of d Return the remainder of d1/d2 with same sign as d1 Return the square root of d Return d1 raised to the power d2

Suppose part of a program is as below double length; length = 5.5; length = 7.0; cout << length; You will get 7.0 as output. a = a+2; //this statement will first evaluate a+2 and then store the value back into variable a (it is implied that the variable a must have been assigned a value before this statement) instead of the above statement we can write a += 2; // this statement has the same effect as the statement above a *= b+5; is same as a =a * (b+5); length /= 5; is same as length = length /5;

Function abs(i)

(header file : stdlib.h) Type Purpose int Return the absolute value of i

- AIMP3_MemoryManager_EventLogUploaded bySyaffiq Sam
- c++ project on supermarketUploaded bys sundararajan
- Railway ReservationUploaded byinbasekar
- BankingUploaded bySamuisssshanus501
- Download Computer Science Technical Aptitude Interview QuestionsUploaded bydxjkcdjjhk
- 12 Java projectsUploaded byAryan Upadhyay
- cprogramming_mock_test_i.pdfUploaded byKetan Takale
- ArraysUploaded byJaichand Ritik
- Discussion 1Uploaded byLucas Moreira
- prog39-47Uploaded byAditya Singh
- Compre Closed BookUploaded byGaurab Dasgupta
- New Text Document (6)Uploaded byAnkur Saxena
- IBM Sample Paper5Uploaded bynkkr
- Untitled 1Uploaded byvinojashu
- MIT6_087IAP10_lec07[1]Uploaded bytaanvimital
- Networking LabUploaded byRam Kumar
- Cs9216 Networking LabUploaded bykvkayal9054
- Networking LabUploaded byVisakh Vijay
- nvccUploaded byLokananda Dhage
- Pi CalculationUploaded byKaew Pao
- Np Lab Manual (1)Uploaded byKiran Reddy
- The Ring programming language version 1.5.2 book - Part 148 of 181Uploaded byMahmoud Samir Fayed
- Dynamic Memory AllocationUploaded byDebadrita
- C MCQ-UNIT-IUploaded bygdeepthi
- Linked Lists CodesUploaded byshreyakedia
- Dharender JangraUploaded bydharenderkumarjangra
- l27 1D ArraysUploaded bysvedanth8
- MCS-011 BLOCK 3Uploaded byAbhishek Veerkar
- BCS52Uploaded byBabji Babu
- 1Z0-147Uploaded bysaidi92

- 142 (1)Uploaded bymoayadalshara
- Hattie What Are the Attributes of Excellent TeachersUploaded byapi-3724678
- Z-Human Computer Interface HCI Seminar ReportUploaded bySurangma Parashar
- LossCoefUploaded byJorge
- Energy and Exergy Analysis of Hybrid Micro-channelUploaded byAnas Alappuzha N S
- Chapter 3 Pair of Linear Equations in Two VariablesUploaded byKuldeep Mishra
- A Discourse of WitUploaded byAlexandra Welch
- Company Profile (1)Uploaded byDendukuri varma
- FOR JATI - Studies in Bhartrharis Vakyapadiya..pdfUploaded byDrn Psk
- How to Remove Recycler Virus From My Drive [Solved]Uploaded byVignesh Chellappan Natarajan
- organic ceramic clay project aims and objectivesUploaded byapi-185034533
- how-to-make-a-line-follower.pdfUploaded bySonu Kumar
- 49024321-panasonic-tx-20la60f-ET.pdfUploaded byEnzo Smith
- HSE Training FeedbackUploaded bypradhan2010
- Facility Management 1Uploaded byRose
- ape3Uploaded byMorgan Gagnon
- FormationsUploaded byDraggon FN
- M-T 5 in 1 OCA vacuum laminating machine Instruction ManualUploaded byXicart Global Cell Phone Repair Parts and Machines Wholesale Online Store
- Q2 05_N155_29847Uploaded byVibhav Upadhyay
- Design FMEAUploaded byAbu Azkha
- Space the New Frontier 1962Uploaded byBob Andrepont
- Infj PersonalityUploaded byMichelle Villanueva
- Arvind Devraj gateUploaded bymahapatrarajeshranjan
- SurveyingUploaded byJP Adviento Ildefonso
- ERP Systems for the 21st CenturyUploaded byaryan_naruto
- Production Catalogue Complete LrUploaded bycambraialopes
- DealerCue Launches BidCue, Vehicle Sourcing and Inventory Management in Your Vincue DashboardUploaded byPR.com
- Umer ZakaUploaded byAzhar Hussain
- 1540-fanuc-r-30ia-vezerlo-adatlapUploaded byAdrian Bratescu
- Guided Reading Lesson - First GradeUploaded byjennifer_quanrud

## Much more than documents.

Discover everything Scribd has to offer, including books and audiobooks from major publishers.

Cancel anytime.