DEV Community

Mirsoli Mirzaahmad õğli
Mirsoli Mirzaahmad õğli

Posted on • Edited on

3 1

Hello Clang | 00

Hello C-lang pic.

Syntax in C

The rules that dictate the correct format of code for a specific programming language are known as syntax.

Examples of syntax in C are:

  • All statements must end with a semicolon,;
  • Keywords and other code elements are case-sensitive

When compiling C code, an error will occur when the syntax of the code is incorrect.

// Statements must end in a semicolon (;)
// correct
printf("Hello World!");

// error
printf("Hello World!")

// Code elements are case sensitive
// correct
printf("Hello World!");

// error
PRINTF("Hello World!");
Enter fullscreen mode Exit fullscreen mode

Escape Sequences

In C, an escape sequence is a non-visual character used within a string.

\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.

// \n acts as a newline in a string
printf("Hello\nWorld!"); // Outputs: Hello
                         //          World!

// \t acts as a tab in a string
printf("Hello\tWorld!"); // Outputs: Hello    World!
Enter fullscreen mode Exit fullscreen mode

Comments in C

In C, comments are text within code that will be ignored 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 is reached.

Block comments begin with a forward slash and asterisk, /* and end with an asterisk and forward slash, */. Block comments can span multiple lines as new lines are part of the comment.

// Comments

/* This review content is
about comments and how they
can be used to document code */

// This is a line comment

/* This is a
block comment */
Enter fullscreen mode Exit fullscreen mode

Compiling C Code with gcc

gcc is an application used to compile C programs into an executable that can run on the target computer. gcc 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.

gcc script.c
gcc script.c -o myProgram
Enter fullscreen mode Exit fullscreen mode

freeCodeCamp data was used

Image of Datadog

The Future of AI, LLMs, and Observability on Google Cloud

Datadog sat down with Google’s Director of AI to discuss the current and future states of AI, ML, and LLMs on Google Cloud. Discover 7 key insights for technical leaders, covering everything from upskilling teams to observability best practices

Learn More

Top comments (0)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

Introducing RTABench

To meet the need for real-time analytics workloads, we developed RTABench, a benchmark designed to test databases with these specific requirements. RTABench focuses on essential query patterns such as joins, filtering, and pre-aggregations.