Essentials of C Program
Let's delve deeper into our introductory program:
Main.c
12345678#include <stdio.h> // preprocessor directive int main() // the main function { printf("Hello, c<>definity!\n"); // print text return 0; // exit }
printf Function
The printf() function displays output on the screen. For our example, it shows the message "Hello, c<>definity!". Text meant for display should be wrapped in double quotes, like this:
printf("some text");
Control Characters
Note
In C,
\nis recognized as a single character, not two separate characters ("\"and"n").
The character sequence \n represents a newline. This means that any content following this sequence will appear on the next line.
Main.c
12345678#include <stdio.h> int main() { printf("Hel\nlo"); return 0; }
Throughout this course, we'll occasionally utilize the \t character for tabulation, which equates to a tab, or 4 spaces.
Main.c
12345678#include <stdio.h> int main() { printf("Hel\tlo"); return 0; }
The Semicolon
The semicolon ; signifies the end of a statement in C. Every statement in C should conclude with a ;. Think of it like the period at the end of a written sentence.
The Return Statement
return is the statement used to end a function and potentially return a value. In the context of the main function, the standard in C requires the use of return 0. While it has specific implications on UNIX systems, it generally indicates an "Exit status" or the successful termination of a program. We'll explore the return statement in greater depth as the course progresses.
Merci pour vos commentaires !
Demandez à l'IA
Demandez à l'IA
Posez n'importe quelle question ou essayez l'une des questions suggérées pour commencer notre discussion
Posez-moi des questions sur ce sujet
Résumer ce chapitre
Afficher des exemples du monde réel
Awesome!
Completion rate improved to 2.63
Essentials of C Program
Glissez pour afficher le menu
Let's delve deeper into our introductory program:
Main.c
12345678#include <stdio.h> // preprocessor directive int main() // the main function { printf("Hello, c<>definity!\n"); // print text return 0; // exit }
printf Function
The printf() function displays output on the screen. For our example, it shows the message "Hello, c<>definity!". Text meant for display should be wrapped in double quotes, like this:
printf("some text");
Control Characters
Note
In C,
\nis recognized as a single character, not two separate characters ("\"and"n").
The character sequence \n represents a newline. This means that any content following this sequence will appear on the next line.
Main.c
12345678#include <stdio.h> int main() { printf("Hel\nlo"); return 0; }
Throughout this course, we'll occasionally utilize the \t character for tabulation, which equates to a tab, or 4 spaces.
Main.c
12345678#include <stdio.h> int main() { printf("Hel\tlo"); return 0; }
The Semicolon
The semicolon ; signifies the end of a statement in C. Every statement in C should conclude with a ;. Think of it like the period at the end of a written sentence.
The Return Statement
return is the statement used to end a function and potentially return a value. In the context of the main function, the standard in C requires the use of return 0. While it has specific implications on UNIX systems, it generally indicates an "Exit status" or the successful termination of a program. We'll explore the return statement in greater depth as the course progresses.
Merci pour vos commentaires !