Exforsys
+ Reply to Thread
Results 1 to 2 of 2

Help in Resolving Error

This is a discussion on Help in Resolving Error within the C and C++ forums, part of the Programming Talk category; I got the following error when I ran my C program -Error C2734: ‘test’: const object must be initialized if ...

  1. #1
    Adrian is offline Senior Member Array
    Join Date
    Apr 2006
    Answers
    124

    Question Help in Resolving Error

    I got the following error when I ran my C program
    -Error C2734: ‘test’: const object must be initialized if not extern

    In my C program I have declared the const as below:
    #include <stdio.h>
    main()
    {
    const float test, sample = test;
    .........
    .........
    }

    Someone help me to resolve this.


  2. #2
    ashlee is offline Senior Member Array
    Join Date
    Apr 2006
    Answers
    108
    It is essential that const data type cannot be not only changed but must be initialized when it is declared. But in your code you have assigned the const data type to a variable which is not advisable. It is because of this reason you are getting the error as -Error C2734: ‘test’: const object must be initialized if not extern. So initialize const value to some constant value
    and your error would be resolved.


Latest Article

Network Security Risk Assessment and Measurement

Read More...