Array-string-Structure ( C Programming Course IOE Multiple Choice ) PDF

Title Array-string-Structure ( C Programming Course IOE Multiple Choice )
Author Praphul Mishra
Course Object Oriented Programming
Institution Tribhuvan Vishwavidalaya
Pages 5
File Size 87.5 KB
File Type PDF
Total Downloads 92
Total Views 149

Summary

Array-string-Structure ( C Programming Course IOE Multiple Choice questions with proper language and no errors. You can develop good understanding on it. )...


Description

1. We want to declare a two-dimensional integer type array called matrix for 3 rows and 5 columns. Which of the following declarations are correct? (a) int matrix [3],[5]; (b) int matrix [5] [3]; (c) int matrix [3,5]; (d) int matrix [3] [5];

2. What is the output of the following program? main ( ) { int m [ ] = { 1,2,3,4,5 } int x, y = 0; for (x = 0; x < 5; x++ ) { y = y + m [ x ]; } printf(“%d”, y) ; } a) b) c) d)

0 5 15 1

3. Which of the following statements will correctly store the concatenation of strings s1 and s2 in string s3? (a) s3 = strcat (s1, s2); (b) strcat (s1, s2, s3); (c) strcpy (s3, strcat (s1, s2)); (d) strcpy (strcat (s1, s2), s3); 4. How do you initialize an array in C? a) int arr[3] = (1,2,3); b) int arr(3) = {1,2,3}; c) int arr[3] = {1,2,3}; d) int arr(3) = (1,2,3); 5. What are the advantages of arrays? a) Objects of mixed data types can be stored b) Elements in an array cannot be sorted c) Index of first element of an array is 1 d) Easier to store elements of same data type

6. Elements in an array are accessed _____________ a) randomly b) sequentially c) exponentially d) logarithmically 7. What will the given statement print if a[20] is an array of int data type? printf(“%d”,a); a) b) c) d)

Value stored in a[0] ASCII value of a Memory location of a[0] Error

8. If str[30] is a string variable, which one is correct way to read the string? a) scanf(“%c”,&str); b) scanf(“%s”,&str); c) scanf(“%s”,str); d) scanf(“%c”,str); 9. The f in scanf and printf function stands for? a) function b) format specifier c) formatted d) is meaningless 10. Which one is correct way of declaring 2D array? a) a[ ][ ]; b) a[ ][ ]={2,4,5,3,8,1,7,8}; c) a[3][4]={2,4,6,8,9,7,5,3,1}; d) a[3][4]; 11. What are the types of array? a) int, float, double, long b) char c) struct, enum d) All of the above

12. What is the output of C program below? int a[5]={3,5,1,6,8}; printf(“ %d”,a[3]); a) b) c) d)

1 3 6 3,5,1,6,8

13. Choose the correct statement for string: a) A string is a group of characters enclosed by double quotes. b) If a string is defined with double quotes, NULL is automatically added at the end. c) Size of a string is without counting NULL character at the end d) All the above 14.What will be the output of following program? int main() { char str[]="JACKIE CHAN"; int i=0; while(str[i] != 0) { printf("%c",str[i]); i++; } return 0; }

a) b) c) d)

Compiler error JJJJJJ JJJJ JACKIE CHAN None of the above

15. Choose a correct statement. a) strrev("abcD") returns Dcba.

b) strcmp("abc", "bcd") returns a negative number c) strcmp("234","123") returns a positive number d) All the above 16. What will be the output of function below? strcmp(str1,str2); a) str1 b) str2 c) -1/0/1 d) str1 and str2 17. Which one is the correct data type for l if l=strlen(str1); ? a) char b) int c) float d) Any 18. What is the size of the structure? a) Size of the largest element of the structure b) Always 128 bytes c) Sum of size of all the elements of the structure d) None 19. What will be the output of following program? int main() { structure campus { int items; char name[10]; }a; strcpy(a.name, "Pulchowk"); a.items=10; printf("%s", a.name); return 0; } a) Pulchowk b) Empty string

c) Compiler error d) None 20. Choose the correct statement a) b) c) d)

Elements of structure can be initialized at the time of declaration Elements of structure cannot be initialized at the time of declaration Only integer members can be initialized at the time of declaration None...


Similar Free PDFs