Exforsys
+ Reply to Thread
Results 1 to 3 of 3

Is there Program Error

This is a discussion on Is there Program Error within the C and C++ forums, part of the Programming Talk category; Recently I and my friend came across a small C program which I have given below: #include <stdio.h> main() { ...

  1. #1
    rachelle is offline Member Array
    Join Date
    Apr 2006
    Answers
    97

    Question Is there Program Error

    Recently I and my friend came across a small C program which I have given below:
    #include <stdio.h>
    main()
    {
    int test[10];
    int b=5;
    int a= b++ + array[b];
    }

    My friend told me the above program would give error. But I told the above program would work fine and the result of value b would be 6. Let us know who is correct. Will the program give error as my friend suggest? Kindly help us know about this.


  2. #2
    Mukhtar Ahmad is offline Junior Member Array
    Join Date
    May 2007
    Answers
    12
    it would give error at compile time because array is not any defined variable


  3. #3
    sammy is offline Senior Member Array
    Join Date
    Apr 2006
    Answers
    144
    I think you have by mistake made a typo error as array[b] instead of putting as test[b]. If t is test[b] in the statement as
    int a= b++ + test[b];
    Then you would have the value of b as 6 as you suggested. But if it is array[b] then it would give compile time error.


    •    Sponsored Ads



Latest Article

Network Security Risk Assessment and Measurement

Read More...