All Exams Test series for 1 year @ ₹349 only
Question

Which of the following statements are correct about the C declarations given below ?

char *p = "Honesty";
char a[ ] = "Honesty";

(a) There is no difference in the declarations and both serve the same purpose.

(b) In both cases the '\o' will be added at the end of the string :Honesty"

(c) The first statement is incorrect since ‘\o’ is not given in the string.

(d) 'p' is a non-const pointer pointing to a non-const string, whereas ‘a’ is a const pointer pointing to a non-const string.

Codes :

This question was previously asked in
UGC NET 2016 Paper 3 Electronic Science Question Paper (10-Jul-2016)
The correct answer is

(b) and (d) are correct.

To determine which statements about the given C declarations are correct, let's analyze each declaration and the corresponding statements.

  1. Declaration Analysis:
    • char *p = "Honesty";
      This statement creates a pointer p that points to a string, which is essentially a pointer to the first character of the string "Honesty". The string is stored in a read-only memory area.
    • char a[] = "Honesty";
      This statement creates an array a of type char and initializes it with the string "Honesty". The array is stored in writable memory, and a null character '\0' is automatically added at the end. The array size is determined by the length of the string plus one for the null character.
  2. Statement Verification:
    • (a) There is no difference in the declarations and both serve the same purpose.
      This is incorrect. The main difference is that p is a pointer and a is an array. The pointer can point to other strings, while the array name acts as a constant pointer and its contents can be modified.
    • (b) In both cases, the '\0' will be added at the end of the string "Honesty".
      This is correct. The null terminator '\0' is automatically appended in both cases, either in the array or logically in the string literal for pointers.
    • (c) The first statement is incorrect since '\o' is not given in the string.
      This is incorrect logic. The escape sequence is '\0' (not '\o'), representing the null character. The null character is assumed even if not explicitly written in string literals, making the statement invalid.
    • (d) 'p' is a non-const pointer pointing to a non-const string, whereas ‘a’ is a const pointer pointing to a non-const string.
      This is correct. p is a pointer that can be made to point to different strings but points to a string constant initially. Conversely, a is an array, and its name acts as a constant pointer that cannot point elsewhere, although its contents can be modified.
  3. Conclusion:
    • The correct options are (b) and (d), as these interpretations accurately reflect the differences and properties of the char *p and char a[] declarations.
Was this answer helpful?

Similar Questions

  1. The function "isalnum( )" returns a non-zero value if the character is alphanumeric and zero otherwise. What is header file to be used in the main program ?

  2. To read a integer variable, find the correct format given below :

    Int m;

  3. Find the correct list, which is the reverse (at all levels) of the given list :

    [[4, 7, 8], 2, 9, [19, 6], 20, 3]

    (i) 3, 20
    (ii) 9, 2
    (iii) [6, 19]
    (iv) [8, 7, 4]

  4. Which of the following is not an infinite loop ?

    (A) int i = 1; 

    while (1) 

         { 

               i++ ;

     }
     

    (B) for ( ; ; ) ;


    (C) int t = 0, f ;

     while (t) 

    {   

                  f = 1; 

    }
     

    (D) int y, x = 0 ; 

    do 

    {

     y = x; 

            while (x == 0);

  5. The three types of loops available in C language are

    i. for
    ii. while
    iii. do-while

    Which loops do not operate without testing the condition even once ?

  6. Match the following :

    List – IList – II 
    a. associativityi. memory storage
    b. # defineii. if-then-else
    c. autoiii. operators with equal precedence
    d. conditional operatoriv. define operator

    Codes :

  7. Assertion (A) : 'C' uses many data types such as integers (short and long) and float etc.

    Reason (R) : Conversion specifier used for short unsigned integer is % lu.

  8. Which bitwise operator is suitable for turning off a particular bit in a number ?

  9. Which storage class is used for the variables that are often required in a program ?

  10. Which is not a proper way of array declaration ?


Important Questions from Miscellaneous

  1. Read the given figure and find the region representing persons who are educated and employed but not confirmed in job.

  2. The magazine in which Mahatma Gandhi mentioned what he wanted the Constitution to do is:

  3. Which gas shields the surface of the earth from ultraviolet radiation from the sun?

  4. Which event is marked as an Intangible Cultural Heritage of Humanity by UNESCO?

  5. Who has been conferred with the rank of the Commander of the Order of the British Empire in 2018?

Need Expert Advice?
Upcoming Exams
MH SET
October 25, 2026
CTET
December 12, 2026
Test Series
UGC NET img
Teaching
UGC NET (Paper 1) 2026 Mock Test Series
476 Tests 1 Tests Free
4.3(72)
English
More Questions from UGC NET

Start Your Preparation with Prepp Mobile App

Download the app from Google Play & App Store
Download the app from Google Play & App Store
Prepp Mobile App