Вы находитесь на странице: 1из 6

1) What is an array? An array is a data structure that is used for the storage of homogeneous data, i.e.

data of the same type. Example: int arr1[10 !integer rray "ith 10 #alues char arr$[10 ! character array "ith 10 #alues float arr%[10 ! float array "ith 10 #alues $) &o" "ill you calculate the memory space occupied 'y an array? (he memory space occupied 'y an array can 'e calculated as )*i+e of element type) x ),um'er of elements in an array) Example int arr1[10 occupies $ 'ytes - 10 elements.$0 'ytes %) Why is it necessary to gi#e the si+e of an array in an array declaration? When an array is declared, the compiler allocates a 'ase address and reser#es enough space in the memory for all the elements of the array. (he si+e is re/uired to allocate the re/uired space. (hus, the si+e must 'e mentioned. 0) What is the difference 'et"een an array and pointer? 1ifference 'et"een arrays and pointers are as follo"s. Array Pointer 1. Array allocates space automatically $.3t cannot 'e resi+ed. %.3t cannot 'e reassigned. 0.*i+e of)array name) gi#es the num'er of 'ytes occupied 'y the array. 1.2ointer is explicitly assigned to point to an allocated space. $.3t can 'e resi+ed using realloc )). %.2ointers can 'e reassigned. 0.*i+eof)pointer name) returns the num'er of 'ytes used to store a pointer #aria'le

4) What are the types of array? 3n general, arrays are classified as: i) *ingle 5 dimensional arrays ii) 6ulti 5 dimensional arrays 7) &o" to declare a single dimensional array? (he general form of a single!dimensional array declaration is: 8storage9class9specifier:8type9/ualifier:8type9mod: type identifier[8si+e9specifier:] 8.initiali+ation 9list: (he terms enclosed "ith in 8 : are optional and the terms sho"n in 'old are the mandatory parts of a single dimensional array declaration. Example: int array[10 ; int aray[ .<1,$,%,0,4,7,=,>,?,0@;

=) Write the syntactic rules a'out the si+e specifier of a single dimensional array i) 3t should 'e a compile time constant expression of integral type. ii) 3t should 'e greater than or e/ual to one. iii) (he si+e specifier is mandatory if an array is not explicitly initiali+ed, i.e. if an initiali+ation list is not present. >. &o" does an array differ from an ordinary #aria'le?

Array As. Brdinary Aaria'le Array is made up of similar data structure that exists in any language. Array is set of similar data types. Array is the collection of similar elements. (hese similar elements could 'e all int or all float or all char etc. Array of char is Cno"n as string. All elements of the gi#en array must 'e of same type. Array is finite ordered set of homogeneous elements. (he num'er of elements in the array is pre!specified. An ordinary #aria'le of a simple data type can store a single element only. Dor example: Brdinary #aria'le: ! int a Array: ! int a[10 ?. What #alues are automatically assigned to those array elements "hich are not explicitly initiali+ed? Ear'age #alues are automatically assigned to those array elements that are not explicitly initiali+ed. 3f gar'age class is auto then array is assumed to contain gar'age #alues. 3f storage class "ere declared static or external then all the array elements "ould ha#e a default initial #alue as +ero.
>) *tate the ad#antages and limitations of an array. Ad#antage: (he time re/uired to access any element in an array of any dimension is almost the same irrespecti#e of its location in an rray! this is clled s direct indexing Fimitations: i) (he memory to an array is allocated at the compile time. ii) Arrays are static in nature. (he si+e cannot 'e expanded or cannot 'e s/uee+ed at the run time iii)(he si+e of an array hs to 'e Cept 'ig enough to accommodate the "orst case. ?) Write the general form of t"o dimensional array. 8storage9class9specifier:8type9/ualifier:8type9mod: type identifier[8ro"9specifier:] [column_specifier] 8.initiali+ation 9list: (he terms enclosed "ith in 8 : are optional and the terms sho"n in 'old are the mandatory parts of a single dimensional array declaration. Example: int array[$ [% ; int aray[ [% .<1,$,%,0,4,7,=,>,?@; 10) Fist out the syntactic rules for initiali+ing elements of t"o dimensional array. 1) (he num'er of initiali+ers in the initiali+ation list should 'e less than or at most e/ual to the num'er of elements )ro" si+e - column si+e) in the array.

$) (he array locations are initiali+ed ro"!"ise %) (he initiali+ers in the list can 'e 'raced to initiali+e elements of the indi#idual ro"s. 11) &o" the elements of $1 array can 'e stored in memory? (here are t"o "ays to store the elements of $1 array 1. Go" maHor order of storage! the elements are stored ro"!"ise $. Iolumn maHor order of storage! the elements are stored column!"ise

1$) &o" are multi!dimensional arrays stored in I? 3n I language the multi!dimensional rrays are stored in the memory 'y using ro" maHor order of storage. 1%) 1oes the I language pro#ide array index out of 'ound checC? ,o, the I language does not pro#ide compile time or run time array index out of 'ound checC. 3f an array is declared as int array[si+e , the maximum #alid index is si+e!1.,othing stops programmer from stepping across an array 'oundary and accessing the array "ith an index greater than si+e!1.

10) 1efine string. (he group of characters, digit and sym'ols enclosed "ithin /uotes is called as *tirng )or) character Arrays. *trings are al"ays terminated "ith JK0L ),MFF) character. (he compiler automatically adds JK0L at the end of the strings. Example: char name[ .<JIL,LBL,LFL,LFL,LEL,LEL,LEL,LEL,LK0L@; char name[ .N&elloN;

14) Why "e donLt use the JOL sym'ol "hile reading a string through scanf ) )? scanf function re/uires an l!#alue as an argument "here it can store the input. *ince the string #aria'le is a character array and the name of an array refers to the address of the first element of the array, the string #aria'le name itself refers to the address of the first element of the array, the string #aria'le name itself refers to the l!#alue.
17) What is a null character? What is the importance of null character in strings? A character constant "ith an A*I33 #alue of +ero is Cno"n as the null character and is "ritten as JK0L. 3t is #ery important to explicitly place the null character at the end "hen character array in initiali+ed "ith the character initiali+ers. Bther"ise it taCes the gar'age characters into string till it encounters a null character. Example: 6ain)) < char str[4 .<JhL,LeL,LlL,LlL,LoL@; printf )P(he string is QsN,str); @ BM(2M(: (he string is hello[

1=) 6ention the #arious string manipulation functions.

1>) . What "ill the output of the follo"ing program 'e? Rinclude8stdio.h: main)) < charname[14 .NmountainN; printf)PQsSn P,name); printf)PQ44KnN,name); printfiL JQ>sKnN,name); printf)PQ!10.0sN,name); @ 1?.Write a program for fi'onocci series using array

$0. Write a I program to concatenate t"o strings.

21.How strings are represented in c language? 22. What is the return type of string in C? There is no such type called String in C. In C string is a character array.

Write a C program for sorting of string in c language. #include<stdio.h> int main(){ int i,j,n; char str[20][20],temp[20]; puts(" nter the no. o! strin" to #e sorted"); scan!("$d",%n); !or(i&0;i<&n;i'') "ets(str[i]); !or(i&0;i<&n;i'')

!or(j&i'(;j<&n;j''){ i!(strcmp(str[i],str[j])>0){ strcp)(temp,str[i]); strcp)(str[i],str[j]); strcp)(str[j],temp); * * print!("+he sorted strin",n"); !or(i&0;i<&n;i'') puts(str[i]); return 0; *

Explain the concept of Array in I.Also sho" the ad#antage of using Array. T1. *earching a particular element from a gi#en list. )Array). T$. *orting to a gi#en list )Array). T%.Iomparison 'et"een 1!1 Array and $!1 array. T0.1isplay the $1 Array in matrix form, tra#ersing the indi#idual ro" and column, accessing different element of matrix, matrix addition, multiplication. Explain any 10 *tring handling 2re!defined Dunction.

Вам также может понравиться