c_review1 - Brief Review of C: Assignment Operator a = 4;...

Info iconThis preview shows pages 1–8. Sign up to view the full content.

View Full Document Right Arrow Icon
Brief Review of ‘C’: Assignment Operator a = 4; b = a * a ; c = b + a; ‘C’ compiler assigns a separate memory location to every new variable on the left side of the assignment operator. if and if…else if (condition expression) statement1; statement2; Statement 2 will be executed anyway. if (condition expression) statement1; else statement2; statement 3; Grades for 220 students of section 1 of COP3223 are available for an exam. Students are to be grouped as per following scheme: group 1 : 85 and above group 2 : 70 to 84 group 3 : 50 to 69 group 4 : below 50
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
It is desired to find out the number of students in each group. #include<stdio.h> int main ( ) { int grade, group1, group2, group3, group4; group1= group2 = group3 = group4 = 0; for (jj = 1; jj <=220; jj++) { printf (“\n enter grade:”); scanf (“%d”, &grade); if (grade >= 85 ) group1++ ; else if ( grade >69 ) group2++ ; else if ( grade >49 ) group3++ ; else group4++; } printf (“\n group1= %d, group2= %d “,group1, group2); printf (“\n group3= %d, group4= %d “,group3, group4); return 0; }
Background image of page 2
Operator precedence: When an expression contains number of operators, they are processed in a particular order ! (unary operators) e.g. – 45 * / % + < <= >= > == != && | | = (assignment operator) if( a < b+c && c==d || a > e )
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
switch statement Days in a month int month, days; switch (month){ case 4 : case 6 : case 9 : case 11 : days = 30; break ; case 2 : days = 28; break ; default : days = 31; }
Background image of page 4
while and do…while Use a while loop to print out the square of the numbers entered by the user. It should stop when the user enters – 999. aa = 1; while (aa != – 999) { printf ("\n new value= "); scanf ("%d",&aa ); printf ("sq of %d is %d", aa , aa*aa); } do { printf ("\nnew value= "); scanf ("%d",&aa); printf ("square of %d is %d", aa, aa*aa); }while ( aa != – 999) alternate version: while (1) { printf ("\nnew value= "); scanf ("%d",&aa); if( aa == – 999) break; printf ("sq of %d is %d", aa, aa*aa); }
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Function calls: # include <stdio.h> int max ( int, int) ; int main ( ) { int a, b, m ; scanf ( “ %d %d “, &a, &b ); m = max( a, b ) ; printf ( “max of %d and %d is %d “,a, b, m ); } int max ( int n1, int n2 ) { if ( n1 > n2) return n1; else return n2; } Formal parameters : Parameters listed in the function definition ( e.g. n1, n2 in example) Actual Parameters : Values being passed on by the calling function ( e.g. Main passing on values of a,b) Number of formal and actual parameters must match The order of parameters must match ( e.g. a to n1 and b to n2) The indicated type for each parameter must match the type in the function definition
Background image of page 6
Do the actual parameter values get changed after the function is called? #include <stdio.h>
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 8
This is the end of the preview. Sign up to access the rest of the document.

This document was uploaded on 06/12/2011.

Page1 / 22

c_review1 - Brief Review of C: Assignment Operator a = 4;...

This preview shows document pages 1 - 8. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online