What is right way to Initialize array?
A. int num[6] = { 2, 4, 12, 5, 45, 5 };
B. int n{} = { 2, 4, 12, 5, 45, 5 };
C. int n{6} = { 2, 4, 12 };
D. int n(6) = { 2, 4, 12, 5, 45, 5 };
Answer & Solution
Option A
What will be the output of the program ?
#include<stdio.h>
void main()
{
int a[5] = {5, 1, 15, 20, 25};
int i, j, m;
i = ++a[1];
j = a[1]++;
m = a[i++];
printf("%d, %d, %d", i, j, m);
}
A. 3, 2, 15
B. 2, 3, 20
C. 2, 1, 15
D. 1, 2, 5
Answer: Option A
What will be the output of following program code?
#include <stdio.h>
int main(void)
{
char p;
char buf[10] = {1, 2, 3, 4, 5, 6, 9, 8};
p = (buf + 1)[5];
printf("%d", p);
return 0;
}
A. 5
B. 6
C. 9
D. Error
E. None of the above
Answer: Option C
An array elements are always stored in ________ memory locations.
A. Sequential
B. Random
C. Sequential and Random
D. None of the above
Option A
What is the maximum number of dimensions an array in C may have?
A. 2
B. 8
C. 20
D. 50
E. Theoratically no limit. The only practical limits are memory size and compilers.
Ans: Option E
Size of the array need not be specified, when
A. Initialization is a part of definition
B. It is a declaratrion
C. It is a formal parameter
D. All of these
Option D
What will be printed after execution of the following code?
void main()
{
int arr[10] = {1,2,3,4,5};
printf("%d", arr[5]);
}
A. Garbage Value
B. 5
C. 6
D. 0
E. None of these
Answer & Solution
Option D
What will be the output of the following program?
void main()
{
char str1[] = "abcd";
char str2[] = "abcd";
if(str1==str2)
printf("Equal");
else
printf("Unequal");
}
A. Equal
B. Unequal
C. Error
D. None of these.
Ans: B
What will be the output of the following code?
void main()
{
int a[10];
printf("%d %d", a[-1], a[12]);
}
A. 0 0
B. Garbage value 0
C. 0 Garbage Value
D. Garbage vlaue Garbage Value
E. Code will not compile
Option D
What will be the output of the program ?
#include
int main()
{
int arr[1] = {10};
printf("%d", 0[arr]);
return 0;
}
A. 1
B. 0
C. 10
D. 6
E. None of these
Option C
Which of the following statements are correct about the program below?
#include<stdio.h>
void main()
{
int size, i;
scanf("%d", &size);
int arr[size];
for(i=1; i<=size; i++)
{
scanf("%d", arr[i]);
printf("%d", arr[i]);
}
}
A. The code is erroneous since the statement declaring array is invalid.
B. The code is erroneous since the subscript for array used in for loop is in the range 1 to size.
C. The code is correct and runs successfully.
D. The code is erroneous since the values of array are getting scanned through the loop.
E. None of these
Answer & Solution
Option A
Which of the following statements are correct about an array?
1. The array int num[26]; can store 26 elements.
2. The expression num[1] designates the very first element in the array.
3. It is necessary to initialize the array at the time of declaration.
4. The declaration num[SIZE] is allowed if SIZE is a macro.
A 1
B.1, 4
C.2, 3
D. 2, 4
E.None of these
Answer & Solution
Option B
You may like the following posts:
A. int num[6] = { 2, 4, 12, 5, 45, 5 };
B. int n{} = { 2, 4, 12, 5, 45, 5 };
C. int n{6} = { 2, 4, 12 };
D. int n(6) = { 2, 4, 12, 5, 45, 5 };
Answer & Solution
Option A
What will be the output of the program ?
#include<stdio.h>
void main()
{
int a[5] = {5, 1, 15, 20, 25};
int i, j, m;
i = ++a[1];
j = a[1]++;
m = a[i++];
printf("%d, %d, %d", i, j, m);
}
A. 3, 2, 15
B. 2, 3, 20
C. 2, 1, 15
D. 1, 2, 5
Answer: Option A
What will be the output of following program code?
#include <stdio.h>
int main(void)
{
char p;
char buf[10] = {1, 2, 3, 4, 5, 6, 9, 8};
p = (buf + 1)[5];
printf("%d", p);
return 0;
}
A. 5
B. 6
C. 9
D. Error
E. None of the above
Answer: Option C
An array elements are always stored in ________ memory locations.
A. Sequential
B. Random
C. Sequential and Random
D. None of the above
Option A
What is the maximum number of dimensions an array in C may have?
A. 2
B. 8
C. 20
D. 50
E. Theoratically no limit. The only practical limits are memory size and compilers.
Ans: Option E
Size of the array need not be specified, when
A. Initialization is a part of definition
B. It is a declaratrion
C. It is a formal parameter
D. All of these
Option D
What will be printed after execution of the following code?
void main()
{
int arr[10] = {1,2,3,4,5};
printf("%d", arr[5]);
}
A. Garbage Value
B. 5
C. 6
D. 0
E. None of these
Answer & Solution
Option D
What will be the output of the following program?
void main()
{
char str1[] = "abcd";
char str2[] = "abcd";
if(str1==str2)
printf("Equal");
else
printf("Unequal");
}
A. Equal
B. Unequal
C. Error
D. None of these.
Ans: B
What will be the output of the following code?
void main()
{
int a[10];
printf("%d %d", a[-1], a[12]);
}
A. 0 0
B. Garbage value 0
C. 0 Garbage Value
D. Garbage vlaue Garbage Value
E. Code will not compile
Option D
What will be the output of the program ?
#include
int main()
{
int arr[1] = {10};
printf("%d", 0[arr]);
return 0;
}
A. 1
B. 0
C. 10
D. 6
E. None of these
Option C
Which of the following statements are correct about the program below?
#include<stdio.h>
void main()
{
int size, i;
scanf("%d", &size);
int arr[size];
for(i=1; i<=size; i++)
{
scanf("%d", arr[i]);
printf("%d", arr[i]);
}
}
A. The code is erroneous since the statement declaring array is invalid.
B. The code is erroneous since the subscript for array used in for loop is in the range 1 to size.
C. The code is correct and runs successfully.
D. The code is erroneous since the values of array are getting scanned through the loop.
E. None of these
Answer & Solution
Option A
Which of the following statements are correct about an array?
1. The array int num[26]; can store 26 elements.
2. The expression num[1] designates the very first element in the array.
3. It is necessary to initialize the array at the time of declaration.
4. The declaration num[SIZE] is allowed if SIZE is a macro.
A 1
B.1, 4
C.2, 3
D. 2, 4
E.None of these
Answer & Solution
Option B
How would
you use qsort() function to sort the name stored in an array of pointers to
string?
Is it better to use a pointer to navigate an array of values,or is it better to
use a subscripted array
name?
What is the difference between null array and an empty array?
How to remove duplicate elements from an
array
Can the sizeof operator be used to tell the size of an array passed to a
function?
Is it better to use a pointer to navigate an array of values,or is it better to
use a subscripted array
name?
WAP to store elements of last col in 1st col and so on.
When does the compiler not implicitly generate the address of the first element
of an array?
Write a program to delete an element from an array?
Can the sizeof operator be used to tell the size of an array passed to a
function?
Code for swapping of two numbers without using temporary variable using
C.
Write a program to insert an element in a linear array
array?
how to print 2 dimensional array in descending order?
Can the size of an array be declared at
runtime?
Array is an lvalue or
not?
Write a program using an array that computes the sum and the average of nth
input values from the keyboard and prints the calculated sum and average.
what will happen if we try to store more number of elements than specified in
array size?
Does mentioning the array name gives the base address in all the
integers?
Can we add the name as "Mixed Arrays" instead of the name given as
"Structures" in c?why the name structure is given?
thanks for array topics in c language
ReplyDelete