logo

CuriousTab

CuriousTab

Discussion


Home C Programming Strings Comments

  • Question
  • What will be the output of the program?
    #include<stdio.h>
    
    int main()
    {
        char str1[] = "Hello";
        char str2[] = "Hello";
        if(str1 == str2)
            printf("Equal\n");
        else
            printf("Unequal\n");
        return 0;
    }
    


  • Options
  • A. Equal
  • B. Unequal
  • C. Error
  • D. None of above

  • Correct Answer
  • Unequal 

    Explanation
    Step 1: char str1[] = "Hello"; The variable str1 is declared as an array of characters and initialized with a string "Hello".

    Step 2: char str2[] = "Hello"; The variable str2 is declared as an array of characters and initialized with a string "Hello".

    We have use strcmp(s1,s2) function to compare strings.

    Step 3: if(str1 == str2) here the address of str1 and str2 are compared. The address of both variable is not same. Hence the if condition is failed.

    Step 4: At the else part it prints "Unequal".


    Strings problems


    Search Results


    • 1. What will be the output of the program?
      #include<stdio.h>
      #include<string.h>
      
      int main()
      {
          char str1[20] = "Hello", str2[20] = " World";
          printf("%s\n", strcpy(str2, strcat(str1, str2)));
          return 0;
      }
      

    • Options
    • A. Hello
    • B. World
    • C. Hello World
    • D. WorldHello
    • Discuss
    • 2. What will be the output of the program?
      #include<stdio.h>
      #include<string.h>
      
      int main()
      {
          static char s[] = "Hello!";
          printf("%d\n", *(s+strlen(s)));
          return 0;
      }
      

    • Options
    • A. 8
    • B. 0
    • C. 16
    • D. Error
    • Discuss
    • 3. Which of the statements is correct about the program?
      #include<stdio.h>
      
      int main()
      {
          int i=10;
          int *j=&i;
          return 0;
      }
      

    • Options
    • A. j and i are pointers to an int
    • B. i is a pointer to an int and stores address of j
    • C. j is a pointer to an int and stores address of i
    • D. j is a pointer to a pointer to an int and stores address of i
    • Discuss
    • 4. Which of the following statements correct about k used in the below statement?
      char ****k;

    • Options
    • A. k is a pointer to a pointer to a pointer to a char
    • B. k is a pointer to a pointer to a pointer to a pointer to a char
    • C. k is a pointer to a char pointer
    • D. k is a pointer to a pointer to a char
    • Discuss
    • 5. Which of the following statements correctly declare a function that receives a pointer to pointer to a pointer to a float and returns a pointer to a pointer to a pointer to a pointer to a float?

    • Options
    • A. float **fun(float***);
    • B. float *fun(float**);
    • C. float fun(float***);
    • D. float ****fun(float***);
    • Discuss
    • 6. What will be the output of the program?
      #include<stdio.h>
      #include<string.h>
      
      int main()
      {
          char str[] = "India\0\CURIOUSTAB\0";
          printf("%d\n", strlen(str));
          return 0;
      }
      

    • Options
    • A. 10
    • B. 6
    • C. 5
    • D. 11
    • Discuss
    • 7. What will be the output of the program?
      #include<stdio.h>
      #include<string.h>
      
      int main()
      {
          char str[] = "India\0\CURIOUSTAB\0";
          printf("%s\n", str);
          return 0;
      }
      

    • Options
    • A. CURIOUSTAB
    • B. India
    • C. India CURIOUSTAB
    • D. India\0CURIOUSTAB
    • Discuss
    • 8. What will be the output of the program?
      #include<stdio.h>
      #include<string.h>
      
      int main()
      {
          char str1[5], str2[5];
          int i;
          gets(str1);
          gets(str2);
          i = strcmp(str1, str2);
          printf("%d\n", i);
          return 0;
      }
      

    • Options
    • A. Unpredictable integer value
    • B. 0
    • C. -1
    • D. Error
    • Discuss
    • 9. What will be the output of the program?
      #include<stdio.h>
      
      int main()
      {
          printf("India", "CURIOUSTAB\n");
          return 0;
      }
      

    • Options
    • A. Error
    • B. India CURIOUSTAB
    • C. India
    • D. CURIOUSTAB
    • Discuss
    • 10. What will be the output of the program?
      #include<stdio.h>
      
      int main()
      {
          char *names[] = { "Suresh", "Siva", "Sona", "Baiju", "Ritu"};
          int i;
          char *t;
          t = names[3];
          names[3] = names[4];
          names[4] = t;
          for(i=0; i<=4; i++)
              printf("%s,", names[i]);
          return 0;
      }
      

    • Options
    • A. Suresh, Siva, Sona, Baiju, Ritu
    • B. Suresh, Siva, Sona, Ritu, Baiju
    • C. Suresh, Siva, Baiju, Sona, Ritu
    • D. Suresh, Siva, Ritu, Sona, Baiju
    • Discuss


    Comments

    There are no comments.

Enter a new Comment