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
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
Hello world
Hello world
Hello world
Hello world
Hello world
Null statement
Reviewed by Mursal Zheker
on
Sabtu, Desember 28, 2013
Rating:
Tidak ada komentar: