Results 1 to 7 of 7

Thread: null statement in c

  1. #1
    Junior Member
    Join Date
    Nov 2007
    Answers
    1

    Question null statement in c

    What are null satements in C? what are the consequences of null statement in c?


  2. #2
    Expert Member
    Join Date
    Apr 2007
    Answers
    500

    Re: null statement in c

    The null statement performs no operation. It has the form:

    >>-;-----------------------------------------------------------><



    A null statement can hold the label of a labeled statement or complete the syntax of an iterative statement.

    Examples of Null Statements

    The following example initializes the elements of the array price. Because the initializations occur within the for expressions, a statement is only needed to finish the for syntax; no operations are required.


    for (i = 0; i < 3; price[i++] = 0) ;

    A null statement can be used when a label is needed before the end of a block statement. For example:

    void func(void) {
    if (error_detected)
    goto depart;
    /* further processing */
    depart: ; /* null statement required */
    }


  3. #3
    Junior Member
    Join Date
    Nov 2007
    Answers
    9

    Re: null statement in c

    Hi!


    The Null statement is nothing but, There is no body within loop or any other statements in C.
    This Statement is used for some time delay or the COMMENT /*C PROGRAM1*/ is also a null statement.

    This example illustrates the null statement:

    eg :1)

    for ( i = 0; i < 10; line[i++] = 0 )
    ;

    eg :2)

    while(i++<10);



    Regards
    Venkat.G


  4. #4
    Junior Member
    Join Date
    Nov 2007
    Answers
    9

    Re: null statement in c

    Hi!

    NULL statement is a statement, it end with semicolon ( ; or {without any body}) wherever we required,we can use this statement for some Time delay.

    if(1);

    for(i=0;i<10;i++);

    while(i++<10)
    {
    }


    Regards
    Venkat.G


  5. #5
    Contributing Member
    Join Date
    Dec 2007
    Answers
    46

    Re: null statement in c

    Quote Originally Posted by susarlasireesha View Post
    The null statement performs no operation. It has the form:

    >>-;-----------------------------------------------------------><


    for (i = 0; i < 3; price[i++] = 0) ;

    A null statement can be used when a label is needed before the end of a block statement. For example:

    void func(void) {
    if (error_detected)
    goto depart;
    /* further processing */
    depart: ; /* null statement required */
    }
    Nice succint explanation. I have one comment and one question on this topic.

    1.
    The for() loop example is a dangerous programming practice. This should never be used as it is very easy to miss the NULL statement and misunderstand the program i.e. readability is shot. So, a better way would be
    for (....)
    /* Null statement */;
    Note the semicolon at the end. Judging by your answer, I think you knew that already.

    2.
    While thinking about the above point, a question occurred to me. Is there a practical use for this NULL statement?? I mean I just can't remember every using it in a professional capacity. If you have used it, I would appreciate some examples. Thanks.


  6. #6

    Re: null statement in c

    A "null statement" is a statement containing only a semicolon; it can appear wherever a statement is expected. Nothing happens when a null statement is executed. The correct way to code a null statement is :


  7. #7
    Junior Member
    Join Date
    Jul 2007
    Answers
    2

    Cool Re: null statement in c

    Hi!

    NULL statement is a statement, it end with semicolon ( ; or {without any body}) wherever we required,we can use this statement for some Time delay.

    if(1);

    for(i=0;i<10;i++);

    while(i++<10)
    {
    }


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
About us
Applying for a job can be a stressful and frustrating experience, especially for someone who has never done it before. Considering that you are competing for the position with a at least a dozen other applicants, it is imperative that you thoroughly prepare for the job interview, in order to stand a good chance of getting hired. That's where GeekInterview can help.
Interact