Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use of null statement in C

Tags:

c

What are typical uses of null statement

; 

in C ?

I know that it is basically used to skip expression where it is expected by the compiler, but here I'm interested only in real-world examples of such use cases.

like image 290
Agnius Vasiliauskas Avatar asked Apr 08 '11 18:04

Agnius Vasiliauskas


People also ask

What is NULL statement in C with example?

for ( i = 0; i < 10; line[i++] = 0 ) ; In this example, the loop expression of the for statement line[i++] = 0 initializes the first 10 elements of line to 0. The statement body is a null statement, since no further statements are necessary.

What is a NULL statement and where is it used?

The NULL statement is an executable statement that does nothing. The NULL statement can act as a placeholder whenever an executable statement is required, but no SQL operation is wanted; for example, within a branch of the IF-THEN-ELSE statement.

How do you write a NULL statement?

To write a null hypothesis, first start by asking a question. Rephrase that question in a form that assumes no relationship between the variables. In other words, assume a treatment has no effect. Write your hypothesis in a way that reflects this.

What is empty statement in C?

An empty statement is used when you no need to perform an operation where a statement is required. It simply transfers control to the end point of the statement. It is also very useful with a while loop with the blank body and label statements.


1 Answers

It's typically the side-effect of a code block that was stripped by the preprocessor, like

#if DEBUG     #define ASSERT(_x) Assert(_x) #else     #define ASSERT(_x) #endif   ASSERT(test);    // Results in null statement in non-debug builds 

That, or in loops where your condition already contains whatever needs to be done in each iteration.

like image 164
EboMike Avatar answered Oct 11 '22 18:10

EboMike