What happens when an array is passed to a function? - ANSWERS-The
address of the 0th element, only, is copied and passed into the function
How are arrays and pointers related? - ANSWERS-Arrays and pointers
are synonymous in terms of how they use to access memory. But, the
important difference between them is that, a pointer variable can take
different addresses as value whereas, in case of array it is fixed. In C ,
name of the array always points to the first element of an array.
Is array notation and pointer notation interchangeable? - ANSWERS-
Pointer notation may always be used with arrays; array notation may
replace pointer notation only if the pointer points to the start of an array
Declare and apply parallel arrays - ANSWERS-Parallel arrays may be
replaced by an array of structs, like votersfirst_name = ['Bones',
'Welma', 'Frank', 'Han', 'Jack'] last_name = ['Smith', 'Seger', 'Mathers',
'Solo', 'Jackles'] height = [169, 158, 201, 183, 172]
what is a string - ANSWERS-A character array which contains
alphabetic, numeric, and special characters, and is terminated by the null
character ('\0')
END OF
PAGE
1
, CPTS 121 FINAL EXAM LATEST
Declare and apply strings - ANSWERS-declare: char str_name[size];int
main(){// declare and initialize stringchar str[] = "Geeks";// print
stringprintf("%s",str);return 0;}
Declare and apply an array of strings - ANSWERS-An array of strings is
simply a 2-dimensional array of characters where each row represents a
string and the max length of each string is determined by the max
number of columnschar a[2][14]; strcpy(a[0], "blah"); strcpy(a[1],
"hmm");
functions <string.h>
strlen ( ) - ANSWERS-returns the length of a string, not including the
null character
functions <string.h>strcpy ( ) - ANSWERS-makes a fresh character-by-
character copy of a string
functions <string.h>strcat ( ) - ANSWERS-appends one string to the end
of another string
functions <string.h>strcmp ( ) - ANSWERS-performs a character-by-
character comparison based on ASCII values.returns 0 if the strings are
END OF
PAGE
2
, CPTS 121 FINAL EXAM LATEST
equal (case does matter), < 0 if string1 is less than string2, or > 0 if
string1 > string2
Declare and apply arrays of pointers - ANSWERS-char
*array_ptrs[10].const int MAX = 3; int main () { int var[] = {10, 100,
200}; int i, ptr[MAX]; for ( i = 0; i < MAX; i++) { ptr[i] = &var[i]; /
assign the address of integer. / } for ( i = 0; i < MAX; i++) {
printf("Value of var[%d] = %d\n", i, ptr[i] ); } return 0; }
Distinguish between scanf ( ) and gets ( ) related to strings -
ANSWERS-scanf() reads input until it encounters whitespace, newline
or End Of File(EOF) whereas gets() reads input until it encounters
newline or End Of File(EOF), gets() does not stop reading input when it
encounters whitespace instead it takes whitespace as a string.scanf can
read multiple values of different data types whereas gets() will only get
character string data.
what is a structure - ANSWERS-A collection of related fields or
variables under one name.May be used to describe real world objects
Declare and apply structs - ANSWERS-declare:
struct Books { char title[50]; char author[50]; char subject[100]; int
book_id; };
END OF
PAGE
3