İnfografik
← Ünite 1
Computer Programming 2

Ünite 1: Chapter 18: C++ As a Better C; Introducing Object Technology

C Standard Library Functions
Functions like printf and scanf are not built-in keywords of the C language. Instead, they reside in standard libraries, and the compiler relies on the linker to bind them into the final executable.
The Entry Point Requirement
Every valid C program must contain exactly one function named main. Execution of the program always starts at the first statement of main, regardless of where it is placed in the file.
The Semicolon Terminator
Every statement in C must end with a semicolon (;). Omitting this character is one of the most common syntax errors, causing the compiler to fail during build time.
The Double Backslash Escape
Because the backslash (\) is reserved as the escape character, printing a literal backslash requires the sequence '\\'. This tells the compiler to treat the second backslash as plain text.

Anahtar Kavramlar

CommentNon-executable text inserted into a program using // or /*...*/ to document code and improve readability. They are completely ignored by the compiler and do not generate machine code.
Preprocessor DirectiveAn instruction starting with a hash symbol (#) that is processed by the C preprocessor before compilation begins. An example is #include <stdio.h>, which imports standard input/output header information.
White SpaceCharacters such as spaces, tabs, and blank lines that are used to format code for human readability. They are normally ignored by the C compiler during the compilation process.
FunctionA reusable program building block or subroutine that performs a specific task. Every C program must contain at least one function, which must be named main.
main FunctionThe mandatory entry point of every C program where execution begins. It is defined with an integer return type as int main( void ).
BlockA group of statements enclosed within a pair of braces ({}) that defines the body of a function or a control structure.
StringA sequence of characters enclosed in double quotation marks, also referred to as a character string, message, or literal, used as data or output.
StatementA complete instruction in C that directs the computer to perform an action, ending with a terminating semicolon (;).
Escape CharacterThe backslash (\) character, which signals to the compiler that the following character in a string represents a special formatting action rather than literal text.
Escape SequenceA combination of an escape character and a control character, such as \n for newline or \" for a double quote, used to format output text.
LinkerA program that runs after compilation to locate standard library functions used in the code and insert their executable calls into the final object program.
ExecutableThe final, completed program file produced by the linker that is ready to be run by the computer's operating system.
VariableA named location in the computer's memory where a value can be stored, updated, and retrieved during the execution of a program.
IdentifierA valid name in C consisting of letters, digits, and underscores that does not begin with a digit, used to name variables and functions.
Case SensitivityThe compiler feature where uppercase and lowercase letters are treated as distinct, meaning identifiers like sum and Sum are completely separate.
PromptA printed message displayed on the screen that instructs the user to take a specific action, such as entering data.
scanf FunctionA standard library function that reads formatted input from the standard input device, which is typically the keyboard.
Address Operator (&)An operator used before a variable name in scanf to pass the exact memory address of the variable, allowing the function to store input data there.
Interactive ComputingA style of computing where a dialogue is established between the user and the computer through alternating prompts and inputs.
Binary OperatorAn operator that performs calculations or actions using exactly two operands, such as the addition (+) or assignment (=) operators.
Destructive Memory OperationThe process where writing a new value into a memory location automatically overwrites and erases the previous value stored there.
Nondestructive Memory OperationThe process where reading a value from a memory location retrieves the data for calculations while leaving the stored value unchanged.
Remainder Operator (%)An arithmetic operator that calculates the remainder left over after integer division, applicable only to integer operands.
Operator PrecedenceThe set of rules that determines the precise order in which operators are evaluated in a multi-operator mathematical expression.
puts FunctionA secure standard library function that displays a string argument on the screen and automatically appends a terminating newline character.

Diğer Önemli Bilgiler

Linker Error Detection

If a standard library function name like printf is misspelled as 'print', the compiler will not flag it as a syntax error. Instead, the linker will fail because it cannot find a matching library function.

Case Sensitivity in Identifiers

C treats uppercase and lowercase letters as completely distinct. For example, the identifiers 'a1' and 'A1' are stored in separate memory locations and represent different variables.

The Address Operator in scanf

The scanf function requires the ampersand (&) operator before variable names, such as &integer1. This passes the memory address of the variable rather than its current value.

Integer Division Truncation

In C, dividing two integers always results in an integer. Any fractional part is truncated, meaning that the expression 7 / 4 evaluates to 1, not 1.75.

Modulus Operator Constraints

The remainder operator (%) can only be used with integer operands. Attempting to use the % operator with floating-point numbers will result in a compilation error.

Straight-Line Form Requirement

Arithmetic expressions must be written in straight-line form, such as a/b, to be accepted by compilers. Standard algebraic fractional notation is not valid syntax.

Redundant Parentheses

Programmers can use unnecessary parentheses, known as redundant parentheses, to group subexpressions. This is a recommended practice to make complex calculations easier to read.

Associativity of Assignment

While almost all arithmetic and relational operators associate from left to right, the assignment operator (=) associates from right to left, evaluating the right-side expression first.

C Keywords Restriction

Keywords such as 'int' and 'if' have predefined meanings in C. They are reserved by the compiler and cannot be used as custom names for variables or functions.

Secure puts Alternative

To prevent security vulnerabilities associated with single-argument printfs, the CERT C Secure Coding Standard recommends using the puts function to print strings that end with a newline.

Two-Argument printf Security

When printing a string without a newline, using printf with two arguments, such as printf("%s", "Welcome "), is a secure coding practice that prevents format string exploits.

Sınavda Dikkat Et

  • Remember that the linker, not the compiler, detects misspelled library function names like printf or scanf because the compiler only leaves placeholder calls.
  • Always use the ampersand (&) before variable names in scanf statements; omitting it is a critical logic error that prevents the program from storing input correctly.
  • Pay close attention to integer division: dividing two integers in C always truncates the decimal part, so 7 / 4 evaluates to 1, not 1.75.
  • Remember that the remainder operator (%) can only be used with integer operands; using it with floats will trigger a compilation error.
  • For secure programming questions, choose 'puts' over 'printf' for single-argument strings that end with a newline, as it prevents format string vulnerabilities.
  • Note that the assignment operator (=) associates from right to left, which is different from almost all other arithmetic and relational operators.
  • Never use C keywords like 'int' or 'if' as variable names, as these are reserved by the compiler and will cause syntax errors.