Main Page

Interesting C/C++ Questions (Turkce Versiyonu)

This page is done to share a set of interesting C/C++ questions that I have come up with/made up. If you would like to add *your interesting questions* it is highly appriciated to be published here (of course, with a reference to your name/site). Do not hesitate to send me e-mail about the content of this page and your questions.

  1. Write a C code to print "Hello world" without using any semicolon (;).
    (a solution)

  2. Take the following structure declerations.

    typedef struct {int data; Element *next} Element;
    Element *head;

    Assume that head is a pointer to the head of a singly linked list (NULL if the list is empty). Without using any additional pointer and helper function, write a function that returns a pointer to the head of the reversed version of the linked list. The prototype of the function:

    Element* reverse(Element *first);

    (a solution)


  3. What does the following code print?

    printf("%d",sizeof(printf("%d",printf("tirtocan")));

    (a solution)


  4. What do the following lines print?

    #define min(a,b) ((a) > (b) ? (a) : (b))

    ~~~~~~~~~~~~~~~
    ~~~~~~~~~~~~~~~

    int a, b;
    a = 10;
    b = 5;

    min(++a,b);
    printf("%d,%d,",a,b);
    min(++a,b+10);
    printf("%d,%d",a,b);


    (a solution)


  5. Write a program taking two integers from user and printing the addition of them, but the restriction that you are allowed to use only one variable (neither dynamic allocation nor use of array).
    (a solution)

  6. Write a program taking two integers from user and swapping their content, but the restriction that you are allowed to use only one variable (neither dynamic allocation nor use of array).
    (a solution)