HOME C C++ PYTHON JAVA HTML CSS JAVASCRIPT BOOTSTRAP JQUERY REACT PHP SQL AJAX JSON DATA SCIENCE AI

C Statements


A C statement is an instruction that tells the computer to perform a specific action. Each statement ends with a semicolon ( ; ). A series of statements combined together form a C program. Here's a breakdown of key aspects:



Types of C Statements:

1: Declaration: Defines variables and functions and specifies their data types.

2: Expression: A combination of values, variables, operators, and function calls that evaluates to a single value.

3: Control Flow: Determines the order in which statements are executed, based on conditions (e.g., if, else, switch) and loops (e.g., for, while).

4: Input/Output: Reads data from the user or writes data to the console (e.g., printf, scanf).

5: Function Calls: Invokes functions defined elsewhere in the program to perform tasks.

6: Compound Statements: Groups multiple statements within curly braces {}.

Example

#include

int main() {

printf("Hello CodeLines!");

return 0;

}



Output


Hello Cpdelines!



It is important that you end the statement with a semicolon ;

If you forget the semicolon (;), an error will occur and the program will not run:

Example

#include

int main() {

printf("Hello CodeLines!")

return 0;

}



Output

Hello CodeLines!



Many Statements

Most C programs contain many statements.

The statements are executed, one by one, in the same order as they are written:

Example

#include

int main() {

printf("Hello CodeLines!");

printf("Have a good day!");

return 0;

}



Output

Hello CodeLines!Have a good day!



Example explained

From the example above, we have three statements:

printf("Hello World!");

printf("Have a good day!");

return 0;

1.The first statement is executed first (print "Hello World!" to the screen).

2.Then the second statement is executed (print "Have a good day!" to the screen).

3.And at last, the third statement is executed (end the C program successfully).