
Syntax in C
? Syntax in C
C has a simple and structured syntax — it’s the foundation of many modern languages. Here's a quick overview of its essential parts:
? Basic Structure of a C Program
int main() { // code here return 0;}
? Key Syntax Rules
Concept | Example | Notes |
---|---|---|
Semicolon | int x = 5; | Ends every statement |
Braces {} | if (x) { ... } | Group statements |
Main Function | int main() | Entry point of every C program |
Comments | // single-line , /* multi */ | Ignored by compiler |
Case-sensitive | int x; ? int X; | C is case-sensitive |
Functions | int sum(int a, int b) | Code blocks that return a value |
? Example: Hello World
#include int main() { printf("Hello, World!\n"); return 0;}
? Input & Output
scanf("%d", &x); // inputprintf("Value: %d", x); // output
? Common Elements
Variables:
int
,char
,float
, etc.Operators:
+
,-
,*
,/
,==
,!=
, etc.Control Flow:
if
,else
,while
,for
,switch
? Example: Simple Calculator
#include <stdio.h>int main() { int a = 5, b = 3; printf("Sum: %d\n", a + b); return 0;}