C Programming Practice - Test 4

Reviewed by Editorial Team
The ProProfs editorial team is comprised of experienced subject matter experts. They've collectively created over 10,000 quizzes and lessons, serving over 100 million users. Our team includes in-house content moderators and subject matter experts, as well as a global network of rigorously trained contributors. All adhere to our comprehensive editorial guidelines, ensuring the delivery of high-quality content.
Learn about Our Editorial Process
| By Nchaudhuri31
N
Nchaudhuri31
Community Contributor
Quizzes Created: 19 | Total Attempts: 9,947
| Attempts: 107 | Questions: 20
Please wait...
Question 1 / 20
0 %
0/100
Score 0/100
1. Which of the following doesn’t match an array

Explanation

The term "heterogeneity" refers to the state of being diverse or composed of different elements. In the context of arrays, it means that the elements within the array are not of the same type or size. However, arrays typically consist of elements that are of the same type and size, making "heterogeneity" the option that doesn't match.

Submit
Please wait...
About This Quiz
C Programming Practice - Test 4 - Quiz

. Dear Learner,
This Assessment consists of questions to test your understanding on - C Programming
You may attempt the same and clarify doubts in WP Group. /... see moreWith your Faculty Member
Regards,
Team SHIVAM see less

2. What is the output? main() { char val[] = {‘a’,’b’,’c’,’\n’,’c’,’\0’}; char *p, *val1, *val2; p = &val[3]; val1 = val; val2 = val; printf(“%d”, ++*p + ++*val1 – 32); }

Explanation

not-available-via-ai

Submit
3. Which of the following character is appended with a string

Explanation

The character '\0' is appended with a string. This is because '\0' represents the null character, which is used to indicate the end of a string in C programming. When a '\0' character is appended to a string, it signifies the termination of the string and is used to ensure that string functions can correctly identify the end of the string.

Submit
4. What is the output? main() { char family[4][20] = { “jesus”, “ram” , “rahim” , “gurunanak” }; char *temp; int count ; temp = family[1]; family[1] = family[2]; // Lvalue required for this line family[2] = temp; // Lvalue required for this line for(count = 0 ;count

Explanation

The correct answer is "Compilation error-Lvalue required". This is because in the lines "family[1] = family[2]" and "family[2] = temp", the left-hand side of the assignment operator is an array element, which is not a valid lvalue. An lvalue is an expression that can appear on the left-hand side of an assignment. Therefore, a compilation error occurs.

Submit
5. An array is a

Explanation

An array is a derived datatype because it is created by combining elements of a basic datatype, such as integers or characters, into a single collection. The array itself can then be used as a datatype to store multiple values of the same type in a contiguous memory space. This allows for efficient access and manipulation of the elements within the array.

Submit
6. What is the the output ? main() { int c[ ]={2.8,3.4,4,6.7,5}; int j,*p=c,*q=c; for(j=0;j

Explanation

not-available-via-ai

Submit
7. Main() { char s[ ]="man"; int i; for(i=0;s[ i ];i++) printf("\n%c%c%c%c",s[ i ],*(s+i),*(i+s),i[s]); }

Explanation

The given code is a C program that prints a sequence of characters using different methods. The code initializes a character array "s" with the value "man". Then, it enters a for loop that iterates until the null character ('\0') is encountered in the array. Inside the loop, it uses different methods to print the characters.

The first printf statement uses the array index notation "s[i]" to print the character at index i, followed by three variations of pointer arithmetic to access the same character.

Therefore, the correct answer is "mmmm aaaa nnnn" as the loop iterates over the characters in the "s" array and prints them four times using different methods.

Submit
8. Void main() { int a[]={0,1,2,3,4}; int * p[]={a,a+1,a+2,a+3.a+4}; printf(“%d”,*(*p)); }

Explanation

The code declares an array 'a' with 5 elements and a pointer array 'p' with 5 elements. Each element of 'p' is assigned the address of the corresponding element in 'a'. The printf statement dereferences the pointer at index 0 of 'p', which is equivalent to dereferencing the pointer at the beginning of 'a'. Therefore, the output will be the value at the first element of 'a', which is 0.

Submit
9. The difference between a character array and string is

Explanation

The correct answer is "appended '\0' in string". This is because in C programming, a string is represented as a character array terminated by a null character ('\0'). This null character indicates the end of the string. On the other hand, a character array may or may not have a null character at the end. The presence of the null character in a string allows for various string manipulation functions to work correctly, while using %s format specifier to print a character array without a null character can result in unpredictable behavior.

Submit
10. What is the output ? void main() { char a[]="12345\0"; int i=strlen(a); printf("here in 3 %d\n",++i); }

Explanation

The code first declares a character array "a" with the value "12345\0". The strlen() function is then used to determine the length of the string, which is 5. The variable "i" is assigned the value of 5. The printf() function is used to print "here in 3" followed by the value of "++i", which is 6. Therefore, the output would be "3 6".

Submit
11. The array name indicates

Explanation

The term "const pointer" refers to a pointer that points to a constant value. In other words, the value being pointed to cannot be modified through the pointer. This is indicated by the "const" keyword before the pointer name.

Submit
12. Main() { struct xx { int x=3; char name[]="hello"; }; struct xx *s=malloc(sizeof(struct xx)); printf("%d",s->x); printf("%s",s->name); }
x); printf("%s",s->name); }">

Explanation

The given code will result in a compiler error because the structure `xx` contains a member `name` which is an array of characters. In C, arrays cannot be initialized inside a structure declaration. Therefore, the initialization of `name` with the string "hello" will cause a compiler error.

Submit
13. Int main() { struct Some Name { int size = 5; char tips[] = "LEARN"; }; struct SomeName ss; printf("\n %d %s",ss.size,ss.tips); return 0; }

Explanation

The given code defines a structure named "SomeName" inside the main() function. The structure has two members, "size" and "tips". However, the initialization of structure members inside the structure definition is not allowed. Therefore, the correct answer is "Structure member can not be initialized".

Submit
14. What is the output ? main() { int i=-1,j=-1,k=0,l=2,m; m=i++&&j++&&k++||l++; printf("%d %d %d %d %d",i,j,k,l,m); }

Explanation

The code initializes variables i and j to -1, k to 0, and l to 2. The expression i++&&j++&&k++||l++ is evaluated. Since i is -1, the expression i++ evaluates to false and the rest of the expression is not evaluated. Therefore, i and j remain -1, k is incremented to 1, l is incremented to 3, and m is assigned the value of l (which is 3). Finally, the printf statement prints the values of i, j, k, l, and m, resulting in the output "0 0 1 3 1".

Submit
15. What will be the output? void main() { char c=125; c=c+10; printf(“%d”,c); }

Explanation

In this code, the variable 'c' is initially assigned the value 125, which is within the range of a char data type. However, when 10 is added to 'c', the resulting value exceeds the range of a char data type. This causes an overflow and the value wraps around to the minimum value of a char data type, which is -128. Therefore, the output will be -121.

Submit
16. What is the output? main() { char *arr = “abc defg”, *x; x = arr; while( *arr != ‘\0’ ) ++*arr++; printf(“%s %s”,arr,x); }

Explanation

The program initializes a character pointer 'arr' with the string "abc defg" and another character pointer 'x'. 'x' is then assigned the value of 'arr'. The program then enters a while loop which increments the value at the memory location pointed to by 'arr' and increments the pointer 'arr' until it encounters the null character '\0'. This effectively increments each character in the string by 1. After the loop, the program prints the value of 'arr' (which is now "bcd!efgh") and 'x' (which is still "abc defg"). Therefore, the output is "bcd!efgh abc defg".

Submit
17. Void main() { int array[]={10,20,30,40}; printf("%d",-2[array]); }

Explanation

In C programming, array indexing can be done using pointer arithmetic. In this case, the expression "-2[array]" is equivalent to "array[-2]". Since arrays are zero-indexed, this means accessing the element at index -2. However, C does not perform bounds checking, so it accesses the memory location before the start of the array. In this case, it accesses the memory location that stores the value 30. Therefore, the correct answer is 30.

Submit
18. What is the output ? #include #include int main() { char *str = "x"; char c = 'x'; char ary[1]; ary[0] = c; printf("%d %d", strlen(str), strlen(ary)); return 0; }

Explanation

The output of the program is "1 (undefined value)".


The program declares a character pointer `str` and initializes it with the string "x". It also declares a character `c` and assigns it the value 'x'. Then, it declares a character array `ary` with size 1 and assigns `c` to its first element.

When the `strlen` function is called on `str`, it returns 1 because it counts the number of characters until it reaches the null terminator '\0'.

However, when the `strlen` function is called on `ary`, it causes undefined behavior because `ary` is not null-terminated. The `strlen` function will continue reading memory until it finds a null terminator, which may result in accessing memory beyond the bounds of `ary`. The output of `strlen(ary)` is therefore unpredictable and can vary.

Submit
19. Main() { char *str1="abcd"; char str2[]="abcd"; printf("%d %d %d",sizeof(str1),sizeof(str2),sizeof("abcd")); }

Explanation

The correct answer is 2 5 5.

In this program, the variable str1 is a pointer to a string literal "abcd", while str2 is an array of characters with a size of 5 (including the null character).

The sizeof operator returns the size of the variable or type in bytes. Since str1 is a pointer, sizeof(str1) will return the size of a pointer (usually 2 or 4 bytes depending on the system).

On the other hand, sizeof(str2) will return the size of the array, which is 5 bytes.

Lastly, sizeof("abcd") will return the size of the string literal "abcd", which is also 5 bytes.

Submit
20. What is the output? main() { char far *ptr1, *ptr2; printf(“%d %d”,sizeof(ptr1),sizeof(ptr2)); }

Explanation

The output of the code is "4 2". The "sizeof" operator is used to determine the size of a data type in bytes. In this case, "ptr1" is declared as a far pointer, which typically requires 4 bytes to store the segment and offset information. However, the size of a pointer can vary depending on the compiler and platform. "ptr2" is declared as a regular pointer, which typically requires 2 bytes. Therefore, the output is 4 for "ptr1" and 2 for "ptr2".

Submit
View My Results

Quiz Review Timeline (Updated): Feb 17, 2023 +

Our quizzes are rigorously reviewed, monitored and continuously updated by our expert board to maintain accuracy, relevance, and timeliness.

  • Current Version
  • Feb 17, 2023
    Quiz Edited by
    ProProfs Editorial Team
  • Jun 11, 2018
    Quiz Created by
    Nchaudhuri31
Cancel
  • All
    All (20)
  • Unanswered
    Unanswered ()
  • Answered
    Answered ()
Which of the following doesn’t match an array
What is the output?...
Which of the following character is appended with a string
What is the output?...
An array is a
What is the the output ? ...
Main()...
Void main()...
The difference between a character array and string is
What is the output ?...
The array name indicates
x); printf("%s",s->name); }" type="button" name="12" value="12" > x); printf("%s",s->name); }" > Main()...
Int main()...
What is the output ? ...
What will be the output?...
What is the output?...
Void main() { int array[]={10,20,30,40}; printf("%d",-2[array]); }
What is the output ? ...
Main()...
What is the output?...
Alert!

Advertisement