0% found this document useful (0 votes)
4 views2 pages

Learn C - Introduction - Learn C - Introduction Cheatsheet - Codecademy

The document is a cheatsheet for learning C programming, covering essential topics such as syntax rules, escape sequences, comments, and compiling code with the gcc compiler. It highlights that all statements must end with a semicolon, explains the use of escape sequences like and , and describes how to write comments in code. Additionally, it provides basic commands for compiling C programs using gcc.

Uploaded by

mariam.m.mansour
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views2 pages

Learn C - Introduction - Learn C - Introduction Cheatsheet - Codecademy

The document is a cheatsheet for learning C programming, covering essential topics such as syntax rules, escape sequences, comments, and compiling code with the gcc compiler. It highlights that all statements must end with a semicolon, explains the use of escape sequences like and , and describes how to write comments in code. Additionally, it provides basic commands for compiling C programs using gcc.

Uploaded by

mariam.m.mansour
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

9/22/24, 11:36 PM Learn C: Introduction: Learn C: Introduction Cheatsheet | Codecademy

Cheatsheets / Learn C: Introduction

Learn C: Introduction

Syntax in C

The rules that dictate the correct format of code for a // Statements must end in a semicolon (;)
specific programming language are known as syntax.
// correct
Examples of syntax in C are:
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 the
syntax of the code is incorrect. printf("Hello World!")

// 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 used // \n acts as a newline in a string


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

// \t acts as a tab in a string


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

https://www.codecademy.com/learn/learn-c-introduction/modules/learn-c-introduction/cheatsheet 1/2
9/22/24, 11:36 PM Learn C: Introduction: Learn C: Introduction Cheatsheet | Codecademy

Comments in C

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


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

/* This is a
block comment */

Compiling C Code with gcc

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


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

Print Share

https://www.codecademy.com/learn/learn-c-introduction/modules/learn-c-introduction/cheatsheet 2/2

You might also like