C Syntax और Structure
In this page:
#include <header.h>
return_type function_name() {
statement;
statement;
}
Semicolons
हर C statement को semicolon से खत्म होना चाहिए ताकि compiler को exactly पता हो कि एक instruction कहाँ रुकता है और अगला कहाँ शुरू होता है; एक भूल जाना beginners की सबसे common errors में से एक है, और यह अक्सर अगली line पर एक confusing error produce करता है।
उदाहरण: Semicolons
// Include standard input/output (printf, scanf)
#include <stdio.h>
// Program execution starts in main()
int main() {
// Declare x and set it to 10
int x = 10;
// Print formatted text to the screen
printf("%d", x);
// Return 0 to signal that the program finished successfully
return 0;
}
Login to try C/C++/Java/PHP code in the editor
Curly Braces
Curly braces { } कई statements को एक single block में group करते हैं, एक function, loop, या conditional की body define करते हुए। compiler matching pair के बीच की हर चीज़ को एक unit मानता है जो साथ execute होती है (या नहीं होती)।
उदाहरण: Curly Braces
// Include standard input/output (printf, scanf)
#include <stdio.h>
// Program execution starts in main()
int main() {
{
// Print formatted text to the screen
printf("Grouped inside braces");
}
// Return 0 to signal that the program finished successfully
return 0;
}
Login to try C/C++/Java/PHP code in the editor
Tokens
एक token सबसे छोटा meaningful हिस्सा है जिसे compiler आपकी source code पढ़ते समय पहचानता है -- keywords, variable names, numbers, + या ; जैसे symbols, और string literals सब individual tokens हैं जिन्हें compiler एक बार में एक parse करता है।
उदाहरण: Tokens
// Include standard input/output (printf, scanf)
#include <stdio.h>
// Program execution starts in main()
int main() {
// Declare total and set it to 100
int total = 100;
// Print formatted text to the screen
printf("%d", total);
// Return 0 to signal that the program finished successfully
return 0;
}
Login to try C/C++/Java/PHP code in the editor
Case Sensitivity
C uppercase और lowercase letters को पूरी तरह अलग characters मानता है, इसलिए main को exactly lowercase में लिखना होता है, और total और Total नाम के variables same program में दो अलग, independent variables हैं।
उदाहरण: Case Sensitivity
// Include standard input/output (printf, scanf)
#include <stdio.h>
// Program execution starts in main()
int main() {
// Declare total and set it to 5
int total = 5;
// Declare Total and set it to 10
int Total = 10;
// Print formatted text to the screen
printf("%d %d", total, Total);
// Return 0 to signal that the program finished successfully
return 0;
}
Login to try C/C++/Java/PHP code in the editor
Indentation
Consistent indentation इस पर असर नहीं डालता कि compiler आपका code कैसे चलाता है -- C whitespace को ignore करता है -- लेकिन यह आपके और दूसरे developers के लिए visually trace करना ज़रूरी है कि कौन से statements किस block के अंदर हैं, खासकर nested loops या conditionals में।
उदाहरण: Indentation
// Include standard input/output (printf, scanf)
#include <stdio.h>
// Program execution starts in main()
int main() {
// Check whether 1
if (1) {
// Print formatted text to the screen
printf("Indentation shows nesting");
}
// Return 0 to signal that the program finished successfully
return 0;
}
Login to try C/C++/Java/PHP code in the editor
- किसी statement के अंत में semicolon भूल जाना, ताकि compiler अगली line पर एक error report करे।
PrintfयाINTलिखना जब C case-sensitive है और सिर्फprintfऔरintexist करते हैं।- एक
{को उसके closing}के बिना छोड़ना, जिससे 'expected } at end of input' error आती है।
Chapter Quiz — Complete all 21 topics to unlock
0/21 topics done
Complete these topics first:
- C Introduction
- C History & Features
- C Environment Setup
- C First Program
- C Syntax & Structure
- C Statements
- C Comments
- C Keywords & Identifiers
- C Data Types
- C Character Data Type
- C Numeric Data Types
- C Decimal (Floating-Point) Numbers
- C sizeof Operator
- C Extended Data Types
- C Type Conversion
- C Booleans
- C Variables
- C Changing Variable Values
- C Multiple Variables
- C Constants
- C Fixed-Width Integers