Sie sind auf Seite 1von 4

C course

Natural language vs programming language

Esperanto or Quenya(Tolkien)
A programming language is defined by a set of certain rigid rules, much more
inflexible.h
Lexicon: determine symbols that could be used.
Syntax: determine the appropriate ways of collating the symbols.
Semantics: helps us to recognize the meaning of every statament expressed.

Computer: responds only to a set of known commands (instruction list/alphabet


language/machine language)
Computer programming: act of composing selected commands in the proper order so
that a desired effect is produced.
High-level programming lenguages: an intermadiate common language between humans
and computers.
Portability: programs can be used on different machine languages and computers.

Compilation: translate from high-level to machine language.


source code = program, source file = file with code
executable file = compile progras without mistakes.
linking = phase of gluing the different excutable codes and the linker start doing
it.
C develop by Dennis Ritchie in XX.
C is a general-porpouse programming language: Use for coding drives, embedded
applications or operating systems

First program in C

Expectations for the program


Algorithm: The sort of structured and semi-formal description of each step.

"#" means that the following line is a preprocessor directive (separate from the
compiler) and pre-read the text of the program and make some modifications.
Preprocessor are controlled entirely by its directives.
"include" is a directive and replace the directive with the file that follows.
Those changes aren't made in the source code, instead are made on a volatile copy
(dissapears after compiler finishes its work).
".h" header file that provides information of the file.
"studio.h" contains a collection of preliminary information about ready-made blocks
(used to write or read text).
"functions" are blocks used to build C programs.
"functions arguments/parameters" is the input data.
"results" output data.
"main" function which always has to appear.
Every function: result,name, parameters and names. This is called "Prototype"
"body" the interior of the function. Start with a opening bracket and end closing
it "{}"
"function invocation": called functions on the code.
Each instruction must end with a semicolon ";".
Each function must have a pair of parentheses, no matter the parameters.
Strings are always enclosed by quotes.
The main functions pauses itself when another function is invocated.
Can write more than one statement per line.
"return" statement that causes the end of the function execution.
"return 1" something went wrong.

Numbers and how the computers see them


integers, are devoid of the fractional part. "int"
floating-point, numbers with or without fractional parts. "float"
type: characteristics of a number which determine its kind, range and application.
Additional conventions: octal and hexadecimal (preceded by "0x") representation.
to print integer: printf("%d\n", IntegerNumberOrExpression);
to print float: printf("%f\n", IntegerNumberOrExpression);

"Variables" are containers to store data. those must have name, type, value.
Restrictions for the varables' name:
-composed of upper-case or lowe case latin letters, digits and the character.
-begin with a letter.
-underline character is a letter
-upper and lowe-case letters are treated as different.

"type" is an attribute which defines which values can be stored.


The variable comes into existences as a result of a declaration.
"declaration" a syntactic structure that binds a name to a specific type.

"=" assignment operator

"keywords" reserved keywords: must not be changed in any way.


"C" is case-sensitive.

Comments

Each comment is equal to a one space.


"/*" comment begins
"*/" comment ends
Comments are used to discard useless code

Compilers differ in assesing nested comments.

2. Floating-point numbers.

Write a point between floating numbers.

Zero can be omitted while float number is written.


Always write a float number as "#." to help the compiler knows which's the type of
the number. (A point makes a double)

Use scientific notation to large numbers with letter "e#" or "E#". The exponent has
to be an integer and the base could be whatever.

Very small numbers are written with "E-#"

declaring a float number: "float PI, Field;"

Convert from int to float automatically can be done.

int values in 32 bits has a range of -2147483648..2147483647. Floats have a limited


capacity.

"implemetation dependent issue" when an large value is store in type "int".


(software portability)

Operators
"Operators": able to operate on the values
"*" multiplication
"/" divisional
Division by zero is forbidden.
"+" plus
"-" substraction or changed the sign of a number.

Unary minus: sign "-#" only requires one number.

Unary plus: used just to preserve the sign

Remainder: "%" both arguments can't be floats.

hierarchy of priorities: some operators act before others.

left-sided binding when the operators are equal.

Additions performed by computers are not always.

higher +- unary
*/%
lower +- binary

Postfix operators
++: increment operator
--: decrement operator
Those can be used before the variable.

Variable++ post-increment operator.


Variable-- post-increment operator.
++Variable pre-increment operator
--Variable pre-increment operator

Priority table

++ -- + - unary
*/%
+ - binary
=

Shortcut operators for two argument operator

variable = variable op expression;


it's the same as:
variable op = expression;

Character type
all strings are treated as arrays.
"char" to store and manipulate characters.

Character type values


-enclosed in a single quotes the value of the string.
-EBCDIC (Extended Binary Coded Decimal Interchange Code)

Literal: uniquely identifies its value.


"\" use as a escape character.
To write " " " in an char type: '\"

Character literals
'\\'

\n denotes a transition to a new line (Line Feed)


\r denotes the return to the beginning of the line (Carriage Return)
\a (as in alarm)
\0 doesn't represent any character;

Character = '\47' -> '\" (treated as an octal digits) ASCII code


Character = '\x27' (treated as a hexadecimal digits) ASCII code

"char" type is treated as a special kind of "int" type


assign a char value to a int variable but without exceeds 255.

2.4 Controlling the flow - absolute basci

"==" equal to
"=" assignment operator (left-side binding)
"=!" not equal
">" greater than
">=" greater than or equal
"<=" less than or equal

Priority table

++ -- + - unary
*/%
+ - binary
< <= > >=
== !=
= += -= *= /= %=

Das könnte Ihnen auch gefallen