You are on page 1of 5

Unit V

1. What is String? How do you know its length? A String is a character array terminated by a null character. The C function strlen() can be used to measure the length of a string. If it is successful, the strlen() function returns the total number of bytes taken by the string; however, the null character in the string is not counted. 2. What are the main differences between a string constant and a character constant? A string constant is a series of characters enclosed by double quotes, while a character constant is a single character surrounded by single quotes. The compiler will append a null character to the array that is initialized with string constant. Therefore, an extra byte has to be reserved for the null character. On the other hand, a character constant takes only one byte in the memory. 3. How do you declare the string? C does not support strings as a data tape. So they are declared as a array of characters. Syntax: char string_name[size]; Where size is number of characters in the string_name Example: char text[25]; 4. What is string concatenation? The process of joining two strings together is called concatenation. In C strcat() function is used to concatenation two string. 5. What is a function? What are the two types of funcations? A function is a self contained program segment that carries out some specific, well-defined task. Two types are, a. Built in functions or library funactions. b. User defined functions.

6. Define User define function? User define functions have to be developed by the user at the time of warning program. Information can be passed to the function via special identifiers called arguments (parameters) and return via return statement. 7. What is a recursive function? Recursive function is a function which calls itself repeatedly until some specified condition is satisfied. 8. What is the difference between local variable and global variable ? The local variable is a variable that is declared inside of all the functions. Its vale used only with in the function. The global variable is a variable that is declared outside of the main function. It is used anywhere in the program. 9. What is the main difference between function declaration and function definition? The main difference between a function declaration and a function definition is that the function definition does not reserve any memory space, nor does it specify what a function does. A function declaration only allocates to a function definition that is placed elsewhere. It also specifies what type of arguments and vales are passed to and returned from the function. A function definition, on the other hand, reserves the memory space and specifies tasks the function can complete. 10.Can a function return a pointer? Yes, In fact, a function a single value that can be any data type except an array or a unction. A pointer value that is, the address returned by a function can refer to a character array, or a memory location that stores another type of data.

11.Give the classification of array The types of array are, a. One Dimensional Array. b. Two Dimensional Array. c. Multi Dimensional Array.

12.Why do you need to use array? In Many cases, we need to declare a set of variables that are of the same data type. Instead of declaring each variable separately, we can declare all variables collectively in the format of an array. Each variable, as an element of the array, can be accessed either through the array element reference or through a pointer that references the array. 13.How do you reference an array be using a pointer? We can use a pointer to reference an array by assigning the start address of an array to the pointer. For example, given a pointer variable ptr_ch and a character array array_ch, we can use one of the following statements to reference the array by the pointer: Ptr_ch=array_ch; Ptr_ch=&array_ch[0]; 14.How do you declare a pointer? Pointer is a variable that contain the address of another variable. Syntax: datatype *pointer_name; Here the data type specifies the type of data to which the pointer points. The pointer_name specifies the name of the pointer. It must preceded with an(*) asterisk. Example: int *a; char *name; 15.What are the advantages of using pointer? Pointers reduce the length and completing of the program. Pointer improves the efficiency of certain routines. It support dynamic memory allocation and dislocation of memory segment. It provides function which can modified their calling arguments 16.Why do you need to use arrays pointers? In many cases, it is convenient to use an array of pointes to point t a set of character strings so that you can access any one of the strings referenced by a corresponding pointer in the array.

17.What is the relation between the address of a variable v and the corresponding pointe variable pv? Any variable declared in a C program has two components. They are, address of the variable and value stored in the variable. Suppose v is a variable. Let us assign the address of v to another variable pv. Thus, Pv=&v This new variable is called a pointer to v, since it points to the location where v is stored in memory. Here pv represents vs address, not its vales. Thus, vp is referred to as a pointer variable. The relationship between pv and v is shown in figure.
Address of v Value of v

Pv

18.What is a structure? A Structure is a single entity representing a collection of data types. Example: Structure library_books { char title[20]; char author[15]; int pages; float price; }; 19.What is a union? A union is a data type in C which allows overlay of more than one variable in the same memory area. Example union result { int marks; float avg; char grade; };

20.How is a structure different from an array? A Structure is a heterogeneous data type where as array is a homogeneous data type. 21.Differentiate between structure and union? The difference between union and structure is in terms of storage; the members within a union share the same storage are. Where as each member within a structure is assigned its own unique storage area. 22.What is mean by nested structure? A structure can be declared within another structure. A Structure within another structure is called a nested structure. The elements of nested structures are accessed using dot (.) operator. 23.Define file? A file is a region of storage on hard disks or an auxiliary storage devices such as magnetic tape or disk where a sequence of data is stored. It contains byes of information. 24.What are the tow ways to link and access the files in a program? The two ways to link and access the files in a program are, High level files (or) library function (or) system calls of operating system. 25.Explain fscanf() and fprintf() functions. fscanf() fscanf (file *fptr, format string, address list) It reads formatted data from a file. It is same as scanf(), except that is accepts a file pointer as the first argument. Fprintf() Fprintf(file *fptr, format string, var_list); It is similar to printf() except that the first argument is a file pointer. It returns a non negative value if successful and returns EOP if an error occurs.

You might also like