3 ms·
C supports variable-length stack-allocated arrays, while C++ doesn't. So code like void f() { int x; scanf("%d", &x); // read from user
by bstamour 9y ago
C supports variable-length stack-allocated arrays, while C++ doesn't. So code like
void f() {
int x;
scanf("%d", &x); // read from user
int numbers[x]; // dynamic
}
is legal C, but not C++.
Also, the C "restrict" keyword doesn't exist in C++ either. Add in C's looser typing rules regarding conversions, and C and C++ are basically sibling languages at this point. Their common ancestor language being K&R-era C.
- saghm 9y ago> C supports variable-length stack-allocated arrays, while C++ doesn't. So > code like > > void f() { > int x; > scanf("%d", &x); // read from user > int numbers[x]; // dynamic > } I just pasted this in a file (and added `#include <cstdio>`) and compiled with g++, and it gave no errors or warnings and produced a *.o file, so maybe it does work?