Changes

Jump to: navigation, search

Week 2

2,070 bytes added, 13:44, 20 May 2010
no edit summary
The Question Mark Operator
''c = a > b ? 100 : 200;''
c 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.''' <u>Function Calls</u> ''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? 100  6 printf returns the number of characters printed (scanf also returns the number of characters input - special note: 200scanf cannot return a number greater than the % symbols in your scanf statement). A function must have one point of entry and one point of exit. Only one return statement per function. <u>The Include Statement</u> ''#include <stdio.h>'' The hash tag (#) tells the compiler how to do things '''BEFORE''' compilation. The #include keyword brings in the code from inside <stdio.h> Header files are usually definitions of functions, classes, templates, etc. <u>The Define Statement</u> A #define statement is a simple search and replace in the current file. ''#define SUM a+b'' ''printf("%d\n", SUM*2);'' This will print 50, not 60. It replaces SUM with a+b then operator precedence allows it to multiply first before addition.  <u>Macros</u>
''#define SUM(x, y) (x+y)''
It replaces an if statement ''printf("%d\n", SUM(i, j)*2);'' ''printf("%d\n", SUM(a, b)*2);'' Those two statements will have ''i+j'' and is much faster''a+b'' instead. If  Why not replace SUM(a, b) to a is greater than +b then 100in the code instead of telling SUM to do it for you before compilation? You might need to change several different things. Could also make it easier to manage code? Another example: ''#define MAX(x, else 200y) ((x)>(y)?(x):(y))'' <u>Conditional Compilation</u> With conditional compilation you can tell the compiler to only compile a section of the code''#define COMPINT 1''''#define COMPDOUBLE 2''''#define COMP COMPINT'' In the code: ''#ifdef COMP == COMPINT'' ''Code'' ''Code'' ''Code''''#endif''
''#ifdef COMP == COMPDOUBLE''
''Code''
''Code''
''Code''
''#else''
''Code''
''Code''
''Code''
''#endif''
Please note: The types 100 It will only compile the first if statement and 200 must be the same type or else it will not workstatement.
<u>Function Calls</u>Thursday May 20, 2010
printf("%d %d, b, b = b + 1);Cursor Movement Low-Level Header Files:
It returns 21 21'''Platforms: Headers: '''BCC: conio. Why? Some compilers stack the arguments hVCC: windows.h and read the last argument firstconio.hLinux: ncurses. Therefore, it would see b as 21 as wellhUnix: curses.h
1
edit

Navigation menu