Difference between revisions of "Week 2"

From CDOT Wiki
Jump to: navigation, search
(Created page with '<u>Reviewing IPC 144</u> The Question Mark Operator c = a > b ? 100 : 200; It replaces an if statement and is much faster. If a is greater than b then 100, else 200. Pleas…')
 
Line 3: Line 3:
 
The Question Mark Operator
 
The Question Mark Operator
  
 +
''c = a > b ? 100 : 200;''
  
c = a > b ? 100 : 200;
+
It replaces an if statement and is much faster. If a is greater than b then 100, else 200.
  
 +
'''Please note: The types 100 and 200 must be the same type or else it will not work.'''
  
It replaces an if statement and is much faster. If a is greater than b then 100, else 200.
+
<u>Function Calls</u>
  
 +
''printf("%d    %d, b, b = b + 1);''
  
Please note: The types 100 and 200 must be the same type or else it will not work.
+
It returns 21    21. Why? Some compilers stack the arguments and read the last argument first. Therefore, it would see b as 21 as well.
  
 +
''a = printf("%d    %d, b, b = b + 1);
  
<u>Function Calls</u>
+
printf("%d\n", a);''
 +
 
 +
What is a?
  
printf("%d    %d, b, b = b + 1);
+
6
  
It returns 21    21. Why? Some compilers stack the arguments and read the last argument first. Therefore, it would see b as 21 as well.
+
printf returns the number of characters printed (scanf also returns the number of characters input - special note: scanf cannot return a number greater than the % symbols in your scanf statement).

Revision as of 12:33, 19 May 2010

Reviewing IPC 144

The Question Mark Operator

c = a > b ? 100 : 200;

It replaces an if statement and is much faster. If a is greater than b then 100, else 200.

Please note: The types 100 and 200 must be the same type or else it will not work.

Function Calls

printf("%d  %d, b, b = b + 1);

It returns 21 21. Why? Some compilers stack the arguments and read the last argument first. Therefore, it would see b as 21 as well.

a = printf("%d  %d, b, b = b + 1);

printf("%d\n", a);

What is a?

6

printf returns the number of characters printed (scanf also returns the number of characters input - special note: scanf cannot return a number greater than the % symbols in your scanf statement).