1

Here's the c code:

#include <stdio.h>

typedef char charray5[5];

charray5 carr1 = { 'a', 'b', 'c', 'd', '\0' };
charray5 carr2 = { 'q', 'w', 'e', 'r', '\0' };
charray5 carr3 = { 'x', 'y', 'z', 'w', '\0' };

charray5* func1() { return &carr1; }
charray5* func2() { return &carr2; }
charray5* func3() { return &carr3; }

char (*(*x[3])())[5] = { func1, func2, func3 };

int main()
{
    printf("func1 = [%c, %c, %c, %c]\n",
        ((*(x[0]))())[0][0], ((*(x[0]))())[0][1],
        ((*(x[0]))())[0][2], ((*(x[0]))())[0][3]);
    printf("func2 = [%c, %c, %c, %c]\n",
        ((*(x[1]))())[0][0], ((*(x[1]))())[0][1],
        ((*(x[1]))())[0][2], ((*(x[1]))())[0][3]);
    printf("func3 = [%c, %c, %c, %c]\n",
        ((*(x[2]))())[0][0], ((*(x[2]))())[0][1],
        ((*(x[2]))())[0][2], ((*(x[2]))())[0][3]);
    return 0;
}

I saw these codes on Geeksforgeeks. By code::blocks IDE, the output is:

Output

func1 = [a, b, c, d]
func2 = [q, w, e, r]
func3 = [x, y, z, w]

But on MSVC 2015, I get nothing on output! No warnings, no Errors and just press any key to continue... will appear after a short delay. I think MSVC 2015 has C99 standard but these codes are for C11 or C17! Am I right? So, what can I do to get similar output on MSVC 2015?

Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
  • 3
    I would not recommend GeeksForGeeks for anything. The style of the code is very poor, it is needlessly obfuscated with all these redundant parentheses, but *technically* I can't see anything wrong with it and it should be ok for a c89 compiler even. – n. m. could be an AI Feb 05 '23 at 06:03
  • Actually, it was attempting to teach how to read complex codes. Anyway, do you know any educational site for learning c programming that is compatible with Microsoft visual studio too? @n.m. – The mayor of kazeroun Feb 05 '23 at 06:07
  • 4
    You don't read this thing. You throw it away and fire the guy who wrote it. Anyway, GeeksForGeeks is not an educational site by any stretch of imagination. I'm afraid there is no educational sites for C which is not a complete disaster. Get a good book. There is "Modern C" by Jens Gustedt and quite a few others. – n. m. could be an AI Feb 05 '23 at 06:17
  • 1
    Is the output window in MSVC vanishing too quickly? – Jonathan Leffler Feb 05 '23 at 06:31
  • Start the project by using "Ctrl + F5" and see if the output appears. – Mark Benningfield Feb 05 '23 at 13:02
  • Damn that! Last night I checked my topic and tested the codes again, surprisingly it ran and got correct and clean output. So, I decided to delete the topic because I thought maybe I was wrong so as not to waste time of anybody else. But today I ran this code again and the same issue was in place. I do not know what is happening! – The mayor of kazeroun Feb 09 '23 at 05:35
  • Not the opposite of what you said @JonathanLeffler – The mayor of kazeroun Feb 09 '23 at 05:36
  • I always do that thing @MarkBenningfield – The mayor of kazeroun Feb 09 '23 at 05:37
  • Thanks for offer that Book. That is several days since I searched for a C book that explains about "Interrupts" topic in C but I found nothing. Of course, there is something in the book you said and I'm happy but it is not detailed and complete. @n.m. – The mayor of kazeroun Feb 09 '23 at 05:56
  • Interrupts are not a part of the C language. – n. m. could be an AI Feb 09 '23 at 06:02
  • I had an old book related to teaching C language, most of its functions are obsolete. In this book, there were lessons about DOS & Bios interruptions. Something about working with Cursor and choosing colors, etc. And I am willing to study those topics in a new version book because the codes of previous book did not work properly on MSVC 2015. Of course, somebody told me that I should config Mingw in my compiler to code with them but I am not sure about the solution! @n.m. – The mayor of kazeroun Feb 09 '23 at 06:59
  • If you want to learn about DOS and BIOS interrupts, you need a DOS and BIOS book, not a C book. That would be a rare thing because computers running DOS are not very popular now in 2023. In a modern OS you don't use interrupts unless you are *writing* an OS. – n. m. could be an AI Feb 09 '23 at 07:45

0 Answers0