Exforsys
+ Reply to Thread
Results 1 to 3 of 3

What happens when declared this way

This is a discussion on What happens when declared this way within the C and C++ forums, part of the Programming Talk category; Is it possible to declare variable inside the for loop like for (int a = 0; a<5;a++) { ...... ...... ...

  1. #1
    Ralph is offline Senior Member Array
    Join Date
    Apr 2006
    Answers
    114

    Exclamation What happens when declared this way

    Is it possible to declare variable inside the for loop like
    for (int a = 0; a<5;a++)
    {
    ......
    ......
    }

    I want to know whether the above declaration of variables is possible in all types of C compilers.


  2. #2
    zsk_00 is offline Member Array
    Join Date
    May 2006
    Answers
    37
    I don't know about all compilers but all the ones that I have worked with did support this functionality.


  3. #3
    caradoc is offline Senior Member Array
    Join Date
    Apr 2006
    Answers
    122
    Yes you can very well do that. This is because you are declaring the loop variable inside the loop variable initialization part of for loop which is supported by all types of C compilers.


    •    Sponsored Ads



Latest Article

Network Security Risk Assessment and Measurement

Read More...