Skip to main content

Null statement

If a statement has only semicolon, then it is called as null statement.

Syntax:
 ;

What is the purpose of null statement?
do nothing

Example 1:
for (i = 0; i < 5; i++)
;   // null statement
Here, the body of the for loop is null statement.

Example 2:
goto label;
........
label:
;
Program needs at least one statement below label.  If we have no valid statement to place below label, then we can put null statement below label as shown above.

Example c program using null statement
 
#include <stdio.h>
main() {
int i;
for (i = 0; i < 5; printf("Hello world\n"), i++)
; // null statement
if (i == 5)
goto err;
printf("You can't execute me!!");
printf(" Yahoooooooooo!!!\n");
err:
; // null statement behind label
}

  Output:
  jp@jp-VirtualBox:~/$ ./a.out
  Hello world
  Hello world
  Hello world
  Hello world
  Hello world



Comments

Popular posts from this blog

restorecrtmode example in c

Header file:     graphics.h Synopsis:        void restorecrtmode();       Description:       restorecrtmode() restores screen mode to text mode. restorecrtmode function in c graphics   #include <graphics.h>   #include <stdlib.h>   #include <stdio.h>   #include <conio.h>   int main(void) {         /* request auto detection */         int gd = DETECT, gmode, err;         int midx, midy;         /* initialize graphics and local variables */         initgraph(&gd, &gmode, "C:/TURBOC3/BGI");         /* read result of initialization */         err = graphresult();         if (err != grOk) {                 /* an error occurred */               ...