← Back to C++ Course | Chapter 1: Introduction & Basics | Lesson 6 of 15

C++ के Statements

एक statement सबसे छोटी complete instruction है जो C++ execute करता है, और एक program मूल रूप से declaration, expression, और compound statements का एक sequence है जो order में execute होता है।
Syntax
cpp
type variable_name = value;   // declaration statement
variable_name = expression;  // expression statement
function_name(arguments);    // function call statement

Statement क्या है?

एक statement C++ में सबसे छोटी complete instruction है जिसे compiler execute करता है, जैसे एक variable declare करना, एक function call करना, या एक expression evaluate करना, और एक C++ program मूल रूप से order में execute होने वाले statements का एक sequence है।

उदाहरण: What is a Statement?

cpp
#include <iostream>

int main() {
	int x = 5;             // declaration statement
	x = x + 1;              // expression statement
	std::cout << x;          // function call statement
	return 0;
}

Expression Statements

एक expression statement एक expression से बनता है, जैसे एक assignment या एक function call, जिसके बाद एक semicolon आता है, और यह statement की सबसे common किस्म है, जो सिर्फ अपने side effect के लिए execute होती है।

उदाहरण: Expression Statements

cpp
#include <iostream>

int main() {
	int total = 0;
	total = total + 10; // expression statement, executed for its side effect
	std::cout << total << std::endl;
	return 0;
}

Compound Statements (Blocks)

एक compound statement, या block, कई statements को curly braces के अंदर एक साथ group करता है, जिससे कई statements को एक single unit की तरह treat किया जा सकता है जहाँ भी language को सिर्फ एक statement चाहिए, जैसे किसी if या loop के अंदर।

उदाहरण: Compound Statements (Blocks)

cpp
#include <iostream>

int main() {
	if (true) {
		int a = 1;
		int b = 2;
		std::cout << a + b << std::endl; // block treated as one statement
	}
	return 0;
}

Declaration Statements

एक declaration statement एक नया variable introduce करता है, इसका type और name specify करते हुए, और optionally एक initial value, उस identifier को बाद के statements में इस्तेमाल के लिए available बनाते हुए।

उदाहरण: Declaration Statements

cpp
#include <iostream>

int main() {
	int score = 100; // declaration statement: type, name, initial value
	std::cout << score << std::endl;
	return 0;
}

Semicolons से Statement Termination

braces में enclosed compound statements को छोड़कर, C++ का हर simple statement एक semicolon से terminate होना चाहिए, जो compiler को exactly बताता है कि एक instruction कहाँ खत्म होता है और अगला कहाँ शुरू होता है।

उदाहरण: Statement Termination with Semicolons

cpp
// Include std::cout and std::cin
#include <iostream>

// Program execution starts in main()
int main() {
	int a = 1; int b = 2;
	// Print to the console with cout
	std::cout << a + b << std::endl;
	// Return 0 to signal that the program finished successfully
	return 0;
}
Related Topics
{# common_mistakes/chapter_summary/browser_support: on Hindi pages the view already swaps in the hi_ translation fields (or blanks these out if untranslated), so this renders correctly for both languages without a lang_code check here. #}
आम गलतियां
  1. int x = 5 जैसे statement के अंत में semicolon छोड़ देना, जो अगली line पर एक compile error cause करता है।
  2. if (x > 0); के बाद एक stray semicolon लगाना, जो empty statement को body बना देता है और बाद वाला block हमेशा चलता है।
  3. यह मान लेना कि { } block के अंदर declared variables closing brace के बाद भी available हैं, जब वे वहाँ out of scope हो जाते हैं।

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.