0% found this document useful (0 votes)
93 views

#Include #Define Increment (X) ++X Int Main (Char PTR "Geeksquiz" Int X 10 Printf ("%S ", Increment (PTR) ) Printf ("%D", Increment (X) ) Return 0 )

The document contains questions about C programming concepts like macros, pointers, arrays, strings, structures and linked lists. It asks about the output of various code snippets testing these concepts. The answers provided explain the behavior and output of each code sample in detail.

Uploaded by

Phan Anh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
93 views

#Include #Define Increment (X) ++X Int Main (Char PTR "Geeksquiz" Int X 10 Printf ("%S ", Increment (PTR) ) Printf ("%D", Increment (X) ) Return 0 )

The document contains questions about C programming concepts like macros, pointers, arrays, strings, structures and linked lists. It asks about the output of various code snippets testing these concepts. The answers provided explain the behavior and output of each code sample in detail.

Uploaded by

Phan Anh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

1. What is output of below program?

#include <stdio.h>
#define INCREMENT(x) ++x
int main()
{
    char *ptr = "GeeksQuiz";
    int x = 10;
    printf("%s  ", INCREMENT(ptr));
    printf("%d", INCREMENT(x));
    return 0;
}

Answer:

-------------------------------------------------------------------------------------------------
2. What is output of below program?

#include <stdio.h>
#define merge(a, b) a##b
int main()
{
    printf("%d ", merge(12, 34));
}

Answer:

-------------------------------------------------------------------------------------------------
3. What is output of below program?

#include <stdio.h>
#define get(a) #a
int main()
{
    // GeeksQuiz is changed to "GeeksQuiz"
    printf("%s", get(GeeksQuiz));
}
Answer:

4. What is output of below program?

#define square(x) x*x


int main()
{
  int x = 36/square(6); // Expended as 36/6*6
  printf("%d", x);
  return 0;
}

Answer:

5. What is output of below program?

#include <stdio.h>
int main()
{
   int x = 1;
   switch (x)
   {
       x = x + 1;
       case 1: printf("Choice is 1");
               break;
       case 2: printf("Choice is 2");
                break;
       default: printf("Choice other than 1 and 2");
                break;                  
   }
   return 0;
}

Answer:

6. What is output of below program?

#include <stdio.h>
int main()
{
   int x = 1;
   switch (x)
   {
       case 2: printf("Choice is 1");
               break;
       case 1+1: printf("Choice is 2");
                break;
   }
   return 0;
}

Answer:

7. What is output of following c snippet?


int main(){
   char *s="Abhas";
   printf("%s",s+s[1]-s[3]); 
   getch();
}

Answer:

8. What is the difference between “const char* p” and “char const* p”?

9. What is the difference between "printf(...)" and "sprintf(...)"?

10. What is output of below program?

int main()
{
    static int i=5;
    if(--i){
        main();
        printf("%d ",i);
    }
}
Answer:

11. What is output of below program?

int main()
{
    int x = 5;
    int const * ptr = &x;
    ++(*ptr);
    printf("%d", x);
   
    return 0;
}
Answer:

12. What is output of below program?

int main()
{
    int x = 5;
    int * const ptr = &x;
    ++(*ptr);
    printf("%d", x);
   
    return 0;
}
Answer:

13. What is output of below program?

# include<stdio.h>
# include<stdlib.h>
 
void fun(int *a)
{
    a = (int*)malloc(sizeof(int));
}
 
int main()
{
    int *p;
    fun(p);
    *p = 6;
    printf("%d\n",*p);
    
    getchar();
    return(0);
}
ANSWER:

14. What is the output of below code:

# include <stdio.h> 
int main()
{
   char str1[] = "GeeksQuiz";
   char str2[] = {'G', 'e', 'e', 'k', 's', 'Q', 'u', 'i',
'z'};
   int n1 = sizeof(str1)/sizeof(str1[0]);
   int n2 = sizeof(str2)/sizeof(str2[0]);
   printf("n1 = %d, n2 = %d", n1, n2);
   return 0;
}
ANSWER:

15. Given two strings like x=”hello” and y=”open”, remove any character from string x which is also
used in string y, thus making the result x=”hll”

Answer:

16. Write a program to find the number of times that a given word(i.e. a short string) occurs in a
sentence (i.e. a long string!). Read data from standard input. The first line is a single word, which is
followed by general text on the second line. Read both up to a newline character, and insert a
terminating null before processing.
Typical output should be:

The word is "the".


The sentence is "the cat sat on the mat".
The word occurs 2 times.

17. Write a program to implement the single linked list as described list of interger. The program
consit of module below:
a. Create linked list
b. Delete a node that have key = x in linked list

You might also like