Hi, I have the next code, actually part of a code (it's C not PHP) PHP: include <stdio.h> const size_t SIZE = 20; int main(void) { char cWord1[SIZE]=" "; //first string char cWord2[SIZE]=" "; //second string .... ...when i compile it, i get the next error message error: variable-sized object may not be initialized SIZE is already defined, why doesn't work?
Arrays declared as local variables may not be initialized as these are created on the stack - declare the 2 arrays as global variables and see if you get the compilation error.
thanks rakoczimrks the problem id that when declaring your variables, for instance char has a single quotation mark, the only thing that has double quotation mark is a string, hope u'll gt it ryt dis tym, THANKS
C is a procedural language all code statements are executed one by one, besides that execution of C program passes through 3 phases 1.preprocessing 2.compilation 3.execution in your question const size_t size = 10; statement is resolved at execution time while in statement char cWord1[SIZE]=" "; value of SIZE is expected at compilation time, so at that time of compilation error will be generated indicating array size is not defined. solution to this problem is 1.resolve in phase 1 i.e. by using preprocessing directive #define(that u already got ) 2.instead of using SIZE=20 and then cWord1[SIZE] use cWord1[20]
sorry but it will not affect replacing " " by "" , as " " means assigning only spaces to character string while "" means not assigning anything.