c89

Are the “C mock tests” at tutorialspoint correct?

微笑、不失礼 提交于 2021-02-08 14:11:25
问题 Since I've been coding C for well over 20 years, I think it was high time for me to take a test! To see if I've learnt anything at all, or if I'm just some fraud posting free but incorrect advice to beginners on the Internet. This site (I'm not affiliated) offers free C tests. https://www.tutorialspoint.com/cprogramming/cprogramming_mock_test.htm. I took test 1 and failed spectacularly with only 34 out of 50! Is this it? Do I have to give up my C programmer career? How good is this

Are the “C mock tests” at tutorialspoint correct?

泄露秘密 提交于 2021-02-08 14:09:29
问题 Since I've been coding C for well over 20 years, I think it was high time for me to take a test! To see if I've learnt anything at all, or if I'm just some fraud posting free but incorrect advice to beginners on the Internet. This site (I'm not affiliated) offers free C tests. https://www.tutorialspoint.com/cprogramming/cprogramming_mock_test.htm. I took test 1 and failed spectacularly with only 34 out of 50! Is this it? Do I have to give up my C programmer career? How good is this

Should I place the parameter storage class specifier in the function definition or in both the declaration and definition?

霸气de小男生 提交于 2021-02-08 12:22:19
问题 I'm working on porting some old K&R code to ANSI C, so I'm writing missing function prototype declarations. A lot of the function definitions have parameters with the register storage class, but I'm not sure if the register storage class specifier can be omitted in the function prototype? With and without the register storage class specific declaration, the code compiles correctly (I tried GCC, VC++ and Watcom C). I could not find any information in the ISO/ANSI C89 standard on what is the

Multiple structures in a single malloc invoking undefined behaviour?

假装没事ソ 提交于 2021-02-07 20:29:56
问题 From Use the correct syntax when declaring a flexible array member it says that when malloc is used for a header and flexible data when data[1] is hacked into the struct , This example has undefined behavior when accessing any element other than the first element of the data array. (See the C Standard, 6.5.6.) Consequently, the compiler can generate code that does not return the expected value when accessing the second element of data. I looked up the C Standard 6.5.6, and could not see how

warning: ISO C90 forbids mixing declarations and code [-Wdeclaration-after-statement] [duplicate]

江枫思渺然 提交于 2021-02-07 17:56:17
问题 This question already has answers here : ISO C90 forbids mixed declarations and code in C (6 answers) Closed 3 years ago . I have this c file #include <stdio.h> int main(int argc, char *argv[]) { int x,i,sum; sum = 0; FILE *fin; fin = fopen("testdata1", "r"); for (i = 0; i < 20; i++ ){ fscanf(fin, "%d", &x); sum += x; } printf("Sum = %d", sum); fclose(fin); return 0; } I compiled it via gcc -ansi -pedantic -Wall app.c -o app While compiling, I kept getting this warning error warning: ISO C90

warning: ISO C90 forbids mixing declarations and code [-Wdeclaration-after-statement] [duplicate]

非 Y 不嫁゛ 提交于 2021-02-07 17:54:00
问题 This question already has answers here : ISO C90 forbids mixed declarations and code in C (6 answers) Closed 3 years ago . I have this c file #include <stdio.h> int main(int argc, char *argv[]) { int x,i,sum; sum = 0; FILE *fin; fin = fopen("testdata1", "r"); for (i = 0; i < 20; i++ ){ fscanf(fin, "%d", &x); sum += x; } printf("Sum = %d", sum); fclose(fin); return 0; } I compiled it via gcc -ansi -pedantic -Wall app.c -o app While compiling, I kept getting this warning error warning: ISO C90

How can I get error message for errno value (C language)?

青春壹個敷衍的年華 提交于 2021-02-07 11:46:14
问题 How can I get error message for errno value (C language)? For example, I can write such file (errno_messages.h): #include <errno.h> char* get_errno_message(void){ switch (errno) { case 0: return ""; break; case EPERM: return "Operation not permitted"; break; case ENOENT: return "No such file or directory"; break; case ESRCH: return "No such process"; break; /* e.t.c. */ default: break; } } But maybe such function is exists already? Best Regards 回答1: I think what you're looking for is strerror

Why can't I “goto default;” or “goto case x;” within a switch selection structure?

会有一股神秘感。 提交于 2021-02-07 11:22:49
问题 Section 6.8.1 of C11 or C99, or section 3.6.1 of C89 all seem to indicate that default and case x (where x is some constant-expression ) are examples of labeled statements, along-side identifier: -style labels that are suitable for use with goto . I'm aware that I could simply place an identifier: -style label directly following the default: or case x: labels. That's not what this question is about. I'm more curious as to whether there is any actual rationale behind prohibiting this kind of

Why can't I “goto default;” or “goto case x;” within a switch selection structure?

醉酒当歌 提交于 2021-02-07 11:22:38
问题 Section 6.8.1 of C11 or C99, or section 3.6.1 of C89 all seem to indicate that default and case x (where x is some constant-expression ) are examples of labeled statements, along-side identifier: -style labels that are suitable for use with goto . I'm aware that I could simply place an identifier: -style label directly following the default: or case x: labels. That's not what this question is about. I'm more curious as to whether there is any actual rationale behind prohibiting this kind of

Why can't I “goto default;” or “goto case x;” within a switch selection structure?

ぐ巨炮叔叔 提交于 2021-02-07 11:22:32
问题 Section 6.8.1 of C11 or C99, or section 3.6.1 of C89 all seem to indicate that default and case x (where x is some constant-expression ) are examples of labeled statements, along-side identifier: -style labels that are suitable for use with goto . I'm aware that I could simply place an identifier: -style label directly following the default: or case x: labels. That's not what this question is about. I'm more curious as to whether there is any actual rationale behind prohibiting this kind of