Knowee
Questions
Features
Study Tools

Consider the following declarations:char a[] = "abhijit";char b[16] = {'a', 'b', 'h', 'i', 'j', 'i', 't'};char *c = "abhijit";char d[16] = "abhijit";Mark the statements as True/False w.r.t. the above.Read each word and number carefully.True False both b and d contain some random data elements of array a[] can not be modified contents of arrays b and c can b modified a points to a constant array, and sayinga[2]= 'x'will cause sgfault c points to a constant string, and sayingc[2] = 'x'will cause a segfault. sizeof(a) and sizeof(c) are 8 bytes b is a string of length 8, with 7 bytes representing 7 characters of "abhijit" and one '\0' byte. b is an array of size 8, with 7 bytes representing 7 characters of "abhijit" and one '\0' byte. sizeof(b) and sizeof(d) are 16 bytes declaration of b is syntactically wrong

Question

Consider the following declarations:char a[] = "abhijit";char b[16] = {'a', 'b', 'h', 'i', 'j', 'i', 't'};char *c = "abhijit";char d[16] = "abhijit";Mark the statements as True/False w.r.t. the above.Read each word and number carefully.True False both b and d contain some random data elements of array a[] can not be modified contents of arrays b and c can b modified a points to a constant array, and sayinga[2]= 'x'will cause sgfault c points to a constant string, and sayingc[2] = 'x'will cause a segfault. sizeof(a) and sizeof(c) are 8 bytes b is a string of length 8, with 7 bytes representing 7 characters of "abhijit" and one '\0' byte. b is an array of size 8, with 7 bytes representing 7 characters of "abhijit" and one '\0' byte. sizeof(b) and sizeof(d) are 16 bytes declaration of b is syntactically wrong

...expand
🧐 Not the exact question you are looking for?Go ask a question

Solution

False - both b and d contain some random data: Array 'b' is initialized with specific characters and 'd' is initialized with a string. There is no random data.

True - elements of array a[] can not be modified: This is false. Elements of array 'a' can be modified as it is not a constant array.

False - contents of arrays b and c can be modified: This is partially true. The contents of array 'b' can be modified but not 'c'. 'c' is a pointer to a string literal and modifying string literal is undefined behavior in C.

False - a points to a constant array, and saying a[2]= 'x' will cause sgfault: This is false. 'a' does not point to a constant array and modifying 'a' will not cause a segmentation fault.

True - c points to a constant string, and saying c[2] = 'x' will cause a segfault: This is true. 'c' is a pointer to a string literal and modifying string literal is undefined behavior in C.

False - sizeof(a) and sizeof(c) are 8 bytes: This is false. sizeof(a) will return 8 (7 characters + null character) but sizeof(c) will return size of pointer which depends on the system (4 bytes on a 32-bit system and 8 bytes on a 64-bit system).

False - b is a string of length 8, with 7 bytes representing 7 characters of "abhijit" and one '\0' byte: This is false. 'b' is not null-terminated and hence it is not a string.

False - b is an array of size 8, with 7 bytes representing 7 characters of "abhijit" and one '\0' byte: This is false. 'b' is an array of size 7 and it is not null-terminated.

True - sizeof(b) and sizeof(d) are 16 bytes: This is true. Both 'b' and 'd' are declared as arrays of size 16.

False - declaration of b is syntactically wrong: This is false. The declaration of 'b' is correct.

This problem has been solved

Similar Questions

Write a program with a function that checks whether or not two-character arrays areidentical, that is whether they have same characters and all characters in correspondingpositions are equal.

Q4: Consider these three statements: char S[10]="trouble"; char *t=S+2; *(t+3) = '\0';The best description of the situation after these three statements is that:Array S now contains the string "troub"Array S now contains the string "tro"Array S now contains the string "tro\0uble"Array S still contains the string "trouble"The code will not compile correctly, and hence cannot be executed

Consider the following two statements: char S[20]="aardvark"; char *p = "baboon"; p = S+2; p[3] = 0;The best description of the situation after these four statements is that:Group of answer choicesThe code can be compiled, but when it is executed it will give a run-time error because pointer p points to restricted memory used to store string constantsThe code will not compile correctly because of type mismatches, and hence cannot be executedPointer p points at the string "rdv"Pointer p points at the string "rdv0rk"Pointer p points at the string "baboo0"

Mark the statements about declaration of arrays, and meaning of arrays as True/False.True False After sayingint a[16];We can say  3[a] to refer to a[3] int a[16];declares an array named a of size 16*sizeof(int) After sayingint a[16];We can say *(3 + a) to refer to a[3] In sayingint a[16];The name a is fixed with the collection of 16 integers and can not be disassociated from it. In sayingint a[16];The valid array indices are 0 to 15. After sayingint a[16];We can say *(a + 3) to refer to a[3]

Indicate true or false for the following statements:a. Every element in an array has the same type.b. The array size is fixed after an array reference variable is declared.c. The array size is fixed after it is created.d. The elements in an array must be of a primitive data type

1/2

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.