C Programming Basic Syntax | Learn the Fundamentals of C Programming Language Structure

Learn the basic syntax of the C programming language. Discover the structure of a C program and the role of keywords, identifiers, operators and punctuation. Get an introduction to data types and variables. Understand how to use comments, preprocessor directives, and header files to organize and document your code. Explore common programming errors and learn how to debug and troubleshoot your code. Get a solid foundation in C programming and start writing your own programs with confidence.

C Programming Basic Syntax | Learn the Fundamentals of C Programming Language Structure
C Programming Basic Syntax [www.dark-coder.com]
C Programming Basic Syntax | Learn the Fundamentals of C Programming Language Structure

C Programming Basic Syntax

Programming in C language is very easy. even tenth-grade students can do this. In this article, we will study the in-depth writing syntax of the C language.

Before deep diving into the C language. we will go Through how the language work and what attributes need to remember.

We already study that C is a mid-level language. It consists of the English alphabet, Special characters, and numbers. Now we know that C is mid-level, we need a compiler to convert the code into an executable format(file) so that the program can run on any compatible machine.

Important Note:

Remember compiler compiles code from top to bottom, And this approach to reading code is called a top-to-bottom approach. Also, the compiler compiles code like from left to right;  

Basic Syntax

C language Consists of tokens, semicolons, comments, identifiers, keywords, white spaces in C, and header files.

What are Tokens in C language? 

The C compiler Can't understand English words directly, So it creat chunks. Those chunks are called tokens.

In simple terms, the C language terms keywords, constants, 

For Example:


printf("Hello, World! \n");
/* The above string contains five tokens.  */
first token = printf
second token = (
The third token = "Hello, World! \n"
The fourth token = )
The fifth token = ;

/* Further classification of the above code */
keywords = printf 
Symbols  = () and ;
String literals = ""

What are Semicolons in C language? 

In English Phrases, we have a dot(.) as an Ending (terminating) statement. That means our line or sentence ends, In the C language, we have a semicolon(;) also called the terminator. Wherever A semicolon is found in C Code the compiler understands that statement ends there. 

The following Two Lines are two Different statements:


printf("Hello, World! \n");
return "area 51";

It is important to remember you should never forget to put a semicolon(;) at the end of each line or C statement. If you forgot to add a semicolon(;), the compiler will give an error.

What are Keywords in language?

In the C language, we have some keywords that are reserved for the compiler to understand what operation should perform. Each keyword has a special meaning in the C language. In general, there is a total of 32 keywords are in C language. All keywords are in High-level Language (In English) so even programmers can easily understand and remember commands. And write C code according to their needs.

Following down we have reserved words.

Signed

Short

Auto

Return

Long

Int

Float

For

goto

IF

Default

Continue

Const

Case

Union

Void

Volatile

Unsigned

extern

enum

else

double

do

Default 

Break

Sizeof

Static

Struct

Switch 

Typedef

While

_Packed

Basics usage of these keywords?

union

I the C programming unions that use the same memory location to store different datatype. It is most likely to Struct, but the major difference in both is that the union uses the same memory to store data (store only one member value at that time), And the struct store its members in a separate location.

volatile

It tells the compiler not to do any optimization on a particular variable. Variables that are mapped to the device register are modified indirectly by the device. In this case, volatile must be used.

struct

Struct is an abbreviation of Structures. In C language struct means group them several related variables into one place(A collection of variables that can be of different types), and each variable that exists in that group is called a member of that structure.

sizeof

It is a special function that uses to calculate the actual size of the data type occupied in memory. It returns size in bytes.

enum

A special kind of keyword is used to define a set of constant integrals or integers that are defined by the developer. it also knows as enumeration but in code just use the short form called enum.

continue

The word continue means resume after interruption. and this keyword is generally used in loops. where ever compiler finds continue it performs the next iteration of the loop, and it skips the rest of the statements in the current iteration.

return

This is used to return a value from functions. that means the execution of the function ends here, no further lines of code will be executed and results should return.

auto, signed, const, extern, register, unsigned

These Keywords serve as Extraordinary functionality. These also use to define the variables in C language.

goto

The special keyword helps developers to redirect the flow of execution. that means the developer can skip some code and jump to somewhere else where he wants the compiler to execute a piece of code.

Void

In C void is a special type of keyword that represents the return type is empty. This means there that function doesn’t return anything. And in simple English void and an empty response.

For, While, Do

These keywords represent the types of loop structures in C. In C each loop serves differently.

Int, Float, Char, Double, Long

These Reserved Keywords are the base of the C programming language. Their function is to separate data according to needs. Each keyword represents a specific data type. The programmer or developer and the compiler can easily understand which type of data should be used for that particular type of variable or what type of data should store.
It is compulsory to use in variable declaration.

Break

It is the most important keyword that helps developers break any loop or switch. Like if a developer wants to Stop execution at a specific time of loop or switch statement then he/she can use the break, to stop its process.

typedef

Typedel is an abbreviation of define type. In the C language typedef means to give a new name to data type.

If, Else, Switch, Case, Default

These Special Keywords are known as conditional operators. Help a developer decide from multiple statements. In simple terms, it is a decision-making programming structure.