Kursinhalt
C Basics
C Basics
How to Run the Program?
To transform our code into specific commands for the processor, we need a compiler. The act of compilation goes through several stages:
An executable file is simply a series of instructions (machine code) meant for the processor. For context, the phrase "Hello, c<>definity"
in machine code might resemble a sequence.
program
01001000011001010110110001101100011011110010110000100000011000110011110000111 110011001000110010101100110011010010110111001101001011101000111100100100001
An intentional error was added to the code below to demonstrate how the C compiler detects and reports issues.
Main
#include <stdio.h> int main() { printf("some text") // Error line return 0; }
The problem arises because the compiler was expecting a semicolon ;
at the end of the printf("some text")
statement. Without the semicolon, the compiler doesn't recognize the end of the statement, causing it to misinterpret the following return 0;
as part of the incomplete printf
line. This leads to the error being reported on the next line, even though the real issue is the missing semicolon after the printf
statement.
Main
#include <stdio.h> int main() { ;; ;;;;;; printf("C language moment\n");;; ;return 0; ;;; }
The C compiler is quite forgiving when it comes to extra semicolons. While they may look odd, multiple ;
instances are treated as empty statements and don't affect the program's behavior. This means the code will still compile and run without issues, even with the excess semicolons. However, it's good practice to avoid unnecessary semicolons to keep your code clean and readable.
Danke für Ihr Feedback!