![]() |
VOOZH | about |
C syntax structures are the building blocks that define how a C program is written and executed. From the way a program starts with main(), to the use of statements, loops, conditionals, and functions, everything follows a strict syntax.
auto, register, static, extern
In C, functions are global by default. The “static” keyword before a function name makes it static. Unlike global functions in C, access to static functions is restricted to the file where they are declared. Therefore, when we want to restrict access to functions, we make them static. Another reason for making functions static can be reuse of the same function name in other files. See this
See Implement your own sizeof for more details.
C is called a mid-level programming language because it combines features of both low-level and high-level languages.
To get 2.5, use floating-point numbers: float a = 5.0 / 2;.
Preprocessor directives start with a # symbol and are processed before the actual compilation begins.
For more information, refer to the article - Preprocessor Directives in C
C language has numerous libraries which contain predefined functions to make programming easier.
For example, if our code needs to take input from the user and print desired output to the screen then ‘stdio.h’ header file must be included in the program as #include <stdio.h>. This header file contains functions like scanf() and printf() which are used to take input from the user and print the content.
For more information, refer to the article - Header Files in C
A macro is a name that is given to a block of C statements as a pre-processor directive.
For more information, refer to the article - Macro vs Functions
Macro:
Function:
A static local variable retains its value between function calls. Unlike normal local variables (which are reinitialized every time a function is called), a static local variable is initialized only once and it persists until the end of the program. An uninitialized static variables have an initial value assigned to 0.
Output:
Count = 1
Count = 2
Count = 3
Here without static, count will initialized in every function call so, count would always print 1.
Call by value | Call by Reference |
|---|---|
| Values of the variable are passed while function calls. | The address of a variable(location of variable) is passed while the function call. |
| Dummy variables copy the value of each variable in the function call. | Dummy variables copy the address of actual variables. |
| Changes made to dummy variables in the called function have no effect on actual variables in the calling function. | We can manipulate the actual variables using addresses. |
| A simple technique is used to pass the values of variables. | The address values of variables must be stored in pointer variables. |
For more information, refer to the article - Pass by Value and Call by Reference
Pass by Value:
Pass by Reference:
C does not support pass by value directly as there are no references (like we have in C++, Java and Python). But we achieve pass by reference using pointers in C.
Every local variable of a function is known as an automatic variable in the C language. Auto is the default storage class for all the variables which are declared inside a function or a block. Auto variables can only be accessed within the block/function they have been declared. We can use them outside their scope with the help of pointers. By default auto keywords consist of a garbage value.
For more information, refer to the article - Storage Classes in C
The extern keyword in C is used to declare a variable or function that is defined in another file or later in the same file. It tells the compiler that the actual memory allocation or definition exists elsewhere. Commonly used in multi-file programs, extern helps share global variables or functions across files without redefining them. It does not allocate memory, only the definition does.
In C format specifiers are used to tell the compiler what type of data will be present in the variable during input using scanf() or output using print().
For more information, refer to the article - Format Specifier in C
For more information, refer to the article - Difference between getc(), getchar(), getch(), getche()
Function pointers or
Calling helper functions inside another function.
Why this matters: This limitation helps enforce cleaner structure, but it challenges beginners coming from languages like Python.
Mimicking nested behavior:
Syntax Error: Mistake in code structure, caught by the compiler. e.g., missing semicolon, unmatched braces.
Logical Error: Code compiles but produces wrong result. Harder to find, requires testing/debugging. e.g., divide by zero.