Array
#include<stdio.h>
int main()
{
int a[5],i,j=5;
for(i=0;i<=4;i++)
{
a[i]= j;
j++;
printf("%d",a[i]);
}
return 0;
}
Bound Checking
Array में bound checking को perform किया जाता है |
जैसे:-
#include<stdio.h>
int main()
{
int a[5],i,j=5;
for(i=0;i<=5;i++)
{
a[i]= j;
j++;
printf("%d",a[i]);
}
return 0;
}
इस condition में run time error आयेगी |
क्यौकी array size 5 है , पर array में variable store करने के लिए loop को 6 बार चलाया जा रहा है |
MCQ
#include<stdio.h>
int main()
{
int a[5],i,j=5;
for(i=0;i<=4;i++)
{
a[i]= j;
j++;
printf("%d",a[i]);
}
return 0;
}
Bound Checking
Array में bound checking को perform किया जाता है |
जैसे:-
#include<stdio.h>
int main()
{
int a[5],i,j=5;
for(i=0;i<=5;i++)
{
a[i]= j;
j++;
printf("%d",a[i]);
}
return 0;
}
इस condition में run time error आयेगी |
क्यौकी array size 5 है , पर array में variable store करने के लिए loop को 6 बार चलाया जा रहा है |
MCQ
1 . When following piece of code is executed, what output will be generated?
#include <stdio.h>
int main()
{
char arr[7]="Network";
printf("%s", arr);
return 0;
}
A) Network
B) N
C) Garbage value
D) Compilation error
2. What will be the output of the following code segment if Hello there is given as input?
2. What will be the output of the following code segment if Hello there is given as input?
char a[20];
scanf("%s", a);
printf("%s", a);
A) Hello there
B) Hello
C) "Hello there"
D) "Hello"
Question
1. What are merits and demerits of array in C?
2 Write a program to find greatest number in an array.
6 Write a program using pointer to find greatest number in an array.
3. How does passing an array as an argument to a function differ from call by value?
8 Write a function which accepts an array of size n containing integer values and returns average of all values. Call the function from main program.
11 Write a ‘C’ program to find out sum of diagonal elements of a matrix using ‘C’.
18 Write a program to input a 3x3 matrix and to print its transpose.
14 Define a two dimensional array ‘int a[10][10]’. Write a ‘C’ program to initialize this array with numbers between 0 and 99. Then print the contents of ‘a’.
2. Write a function to read a two dimensional matrix along with the number of rows and columns in it, from the user. The contents of the array and the number of rows and columns should be passed back to the calling function.
3 The value of S[5] in the segment char s[15] = “ MICROPROCESSOR” is
A) P
B) O
C) R
D) None of the above
Mcq
Disadvantage of array in C is
A) We can easily access each element
B) It is necessary to
declare too many variables
C) It can store only one similar type of data
D) It is difficult to
perform sorting operation on it
True false
1. We can allocate a 2-Dimensional array dynamically.
2. The string "Bilbo Baggins", may be stored in an
array of 13 characters.
3. The lifetime of a
static variable is the duration of your program's execution.
4. Are the three declarations char **apple, char *apple[],
and char apple[][] same?
5 A variable is a string that varies during program
execution.
6 void (*ptr)() is a pointer to a function which receives
nothing and returns nothing.
7 In ‘C’, if you pass an array as an argument to a function,
value of elements in array actually gets passed?
8 An array is a group of related data item that share a
common memory location in RAM.
9 In the declaration int(*p)() p is a pointer to a function
that returns an integer
10 If m = 5, ++m + ++m is equal to 12.
11 The memory required in structure is less than union.
12 The index of an array starts from 1.
13 Functions can return a floating point number
14 A preprocessor directive is a message from compiler to
the linker.
15 NULL pointer is not same as an uninitialized pointer.
16 Structures cannot contain a pointer to itself.
17 In a function two return statements should never occur.
18 The expression a[0] and *a[0] are same for int a[100].
19 Bounds of the array index are checked during execution.
20 . If the two
strings are found to be unequal then strcmp returns difference between the
first nonmatching pair of characters.
Match the following
1.
|
string.h is used to
|
a)
|
strcmp(str1, str2)
|
2.
|
int p(char *a[])
|
b)
|
pp is pointer to an array of integer
|
3.
|
srtlen(“123456”)
|
c)
|
The same data types placed in contiguous memory locations
|
4.
|
pp[i] can be written as
|
d)
|
Accepts an argument which is an array of pointers to characters
|
5.
|
Comparing contents of two character arrays str1 and str2
|
e)
|
Perform operations in string
|
6.
|
An array is a collection of
|
f)
|
6
|
7.
|
int(*pp)[10]
|
g)
|
*(d + i)
|
8.
|
h)
|
Fill in the balnks
a)
|
relational
|
b)
|
register
|
c)
|
static
|
d)
|
index
|
e)
|
int *p( char *a[ ] )
|
f)
|
pointer
|
g)
|
stdin
|
h)
|
fn(int q, char c);
|
i)
|
void
|
j)
|
1. ________ accepts an argument which is an array of
pointers to characters and returns a pointer to an integer quantity.
2. The preferred storage class if fast access is required
for a variable is ________.
3. A function call for a function with the declaration void
fn(int x, char c); is ________.
4. ________ is the file automatically connected to the
keyboard for every program.
5. The ________ operators are used to compare the values of
integers.
6 An array element is accessed using an ________ number.
7 ________ data member can only be used in static functions.
8 ________ cannot be legitimately passed to a function.
9 If the pointer variable ptr holds the address of a char,
the data type of *ptr will be ________.
Question
1. What are merits and demerits of array in C?
2 Write a program to find greatest number in an array.
6 Write a program using pointer to find greatest number in an array.
3. How does passing an array as an argument to a function differ from call by value?
8 Write a function which accepts an array of size n containing integer values and returns average of all values. Call the function from main program.
11 Write a ‘C’ program to find out sum of diagonal elements of a matrix using ‘C’.
18 Write a program to input a 3x3 matrix and to print its transpose.
14 Define a two dimensional array ‘int a[10][10]’. Write a ‘C’ program to initialize this array with numbers between 0 and 99. Then print the contents of ‘a’.
30 Write a ‘C’ function to calculate matrix C such that C=A+B Use suitable loops. Make use of pointers if necessary
32 Write a ‘C’ program to call the above two functions and print Matrix C suitably. Write suitable prototype etc. Use suitable loops. Make use of pointers if necessary
1. Write a program to calculate number of vowels (a, e, i,
o, u) separately in the entered string.
12 Write a ‘C’ program to read an array of names and to sort them in alphabetical order.
12 Write a ‘C’ program to read an array of names and to sort them in alphabetical order.
2. Write a function to read a two dimensional matrix along with the number of rows and columns in it, from the user. The contents of the array and the number of rows and columns should be passed back to the calling function.
3 Write a program using function to read an array from the
user and print the odd number at odd position and prints the even numbers at
even positions. For example input array is 1 2 3 4 and output is 2 1 4 3.
No comments:
Post a Comment