Monday, September 15, 2008

C/C++ abilities that supposed to be acquired:

Able to understand the basic structure of the C / C++ program.

Able to understand and use the basic data types.

Able to recognize and use the keywords and variables.

Able to understand and use the constant, character and escape sequence.

Able to understand and use the C typecasting/promotion.

2.1 What Is A Program?

  • C / C++ programs consist of functions (routines/procedures/methods), one of which must be main() for execution point to start. Every C / C++ program begins execution at the main() function.

2.2 Program Keywords / Reserved Words

  • The keywords used in C/C++ have special meaning to the compiler. The programmer can’t use these words for identifiers such as variable names. The following table is a list of keywords used in ANSI C.

Keyword

Description

auto

An automatic storage class for automatic variable. Normally not explicitly used.

break

Used to force an immediate exit from while, for, do loops and switch-case statement.

case

A label used together with switch statement for selection.

char

A single byte data type, capable holding one character in the character set.

const

A qualifier used to declare variable to specify that its value will not be changed.

continue

Related to break statement, causes the next iteration of the enclosing for, while or do loop to begin. Applies only to loops, not to switch statement.

default

An optional label used together with case label. When there is no case expression matched, default label expression will be executed.

do

Used in do-while loop, repetition where the test condition is at the end of the loop body.

double

A double-precision floating point.

elif

#elif. Preprocessor statement for else-if.

else

Used together with if (if-else) for conditional execution.

endif

#endif. Preprocessor statement for end-if.

enum

Used in declaring enumeration constant. Enumeration is a list of constant integer values.

extern

External storage class. External to all function or globally accessible variable. Variable declared with extern can be accessed by name by any function.

float

Used when declaring floating-point data type.

for

Used in the repetition loop.

goto

A program control statement for branching/jumping to.

if

Used for conditional execution, standalone or with else. #if used for conditional inclusion of the preprocessor directive.

ifdef

#ifdef, if defined; test whether a name is defined.

ifndef

#ifndef, if not defined; test whether a name is not defined.

int

An integer data type, the size of normal integers.

long

A qualifier (long and short) applied to basic data types. short – 16 bits, long-32 bits, int either 16 or 32 bits.

register

Another storage class specifier. Used to advise the compiler to place the variables in machine’s processor register instead of machine’s memory but it is not a mandatory for the compiler.

return

Used to return a value from the called function to its caller. Any expression can follow return. The calling function is free to ignore the returned value and can be no expression after return (no value is returned). For main(), return will pass to system environment, operating system if there is no error.

short

A qualifier (long and short) applied to basic data types. short – 16 bits, long-32 bits, int either 16 or 32 bits.

signed

A qualifier may be applied to char or any integer. For example, signed int. Including the positive and negative integers. For example, integer equivalent range for signed char is -128 and 127 (2’s complement machine).

sizeof

An operator. Shows the number of bytes (occupied or) required to store an object of the type of its operand. The operand is either an expression or a parenthesized type name.

static

A storage class specifier. Local variables (internal variables) that retain their values throughout the lifetime of the program. Also can be applied to external variables as well as functions. Functions declared as static, its name is invisible outside of the file in which it is declared. For an external variables or functions, static will limit the scope of that objects to the rest of the source file being compiled.

struct

A structure specifier for an object that consist a sequence of named members of various types.

switch

Used in a selection program control. Used together with case label to test whether an expression matches one of a member of case’s constant integer and branches accordingly.

typedef

Used to create new data type name.

union

A variable that may hold (at different time) objects of different types and sizes. If at the same time, use struct.

unsigned

A qualifier may be applied to char or any integer. For example, unsigned int. Including the positive integers or zero. For example, integer equivalent range for unsigned char is 0 and 255.

void

Data type that specifies an empty set of values or nonexistence value but pointers (pointers to void) may be assigned to and from pointers of type void *.

volatile

A qualifier used to force an implementation to suppress optimization that could otherwise occur.

while

Used for conditional loop execution. Normally together with the do.

No comments: