HCL Interview Question
Software EngineersCountry: India
Interview Type: Phone Interview
int main(void) {
char *chr_pointer = {"abcdef"};
int *a = chr_pointer;
while (*((char *)a)!= '\0') {
printf("%c\n", *((char *)a));
a = (char *)a + 1;
}
return 0;
}
Compilation error time: 0 memory: 0 signal:0
prog.cpp: In function 'int main()':
prog.cpp:7:30: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]
char *chr_pointer = {"abcdef"};
^
prog.cpp:8:11: error: cannot convert 'char*' to 'int*' in initialization
int *a = chr_pointer;
^
prog.cpp:11:8: error: cannot convert 'char*' to 'int*' in assignment
a = (char *)a + 1;
^
c#.
variant 1.
variant 2.
- zr.roman November 17, 2015