0% found this document useful (0 votes)
5 views

Introduction: Learn C: Introduction Cheatsheet

This document provides an introduction to the C programming language, covering essential syntax rules, such as the requirement for statements to end with a semicolon and the case sensitivity of keywords. It explains the use of escape sequences like for newlines and for tabs, as well as the purpose of comments in code. Additionally, it introduces the gcc compiler, detailing how to compile C programs into executable files.

Uploaded by

Duarte Almeida
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

Introduction: Learn C: Introduction Cheatsheet

This document provides an introduction to the C programming language, covering essential syntax rules, such as the requirement for statements to end with a semicolon and the case sensitivity of keywords. It explains the use of escape sequences like for newlines and for tabs, as well as the purpose of comments in code. Additionally, it introduces the gcc compiler, detailing how to compile C programs into executable files.

Uploaded by

Duarte Almeida
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Cheatsheets / Learn C: Introduction

Learn C: Introduction

Syntax in C

The rules that dictate the correct format of code // Statements must end in a semicolon
for a speci!c programming language are known as
(;)
syntax.
Examples of syntax in C are: // correct
All statements must end with a semicolon, printf("Hello World!");
;
Keywords and other code elements are
case-sensitive // error
When compiling C code, an error will occur when printf("Hello World!")
the syntax of the code is incorrect.

// Code elements are case sensitive


// correct
printf("Hello World!");

// error
PRINTF("Hello World!");

Escape Sequences

In C, an escape sequence is a non-visual character // \n acts as a newline in a string


used within a string.
printf("Hello\nWorld!"); // Outputs:
\n is an escape sequence that adds a newline to
a string. \t is an escape sequence that adds a Hello
tab of spaces to a string. //
World!

// \t acts as a tab in a string


printf("Hello\tWorld!"); // Outputs:
Hello World!
Comments in C

In C, comments are text within code that will be // Comments


ignored by the compiler. They are used to
document code.
Line comments begin with a double forward slash, /* This review content is
// . All text after // will be part of the about comments and how they
comment until a new line is reached.
can be used to document code */
Block comments begin with a forward slash and
asterisk, /* and end with an asterisk and forward
slash, */ . Block comments can span multiple // This is a line comment
lines as new lines are part of the comment.

/* This is a
block comment */

Compiling C Code with gcc


gcc

gcc is an application used to compile C gcc script.c


programs into an executable that can run on the
gcc script.c -o myProgram
target computer. gcc stands for GNU Compiler
Collection.
gcc compiles C code using the code !le as an
un"agged command-line argument. The output
executable !le will be called a.out . The -o
"ag followed by some text can be used to designate
the name of the output executable !le.

Print Share

You might also like