C Programming Questions and Answers 2
C Programming Questions and Answers 2
, M Phil
1 Mention any two features of C language.
5 What is a token?
Keywords, Identifiers.
Keywords are C tokens. All keywords have fixed meanings and these meanings
cannot be changed. They are used for specific purpose. Ex: int, if, for, else etc..
8 What are identifiers?
Identifiers refer to the names of variables, functions and arrays. These are user
defined names and consist of a sequence of letters and digits, with a letter as
a first character.
9 Give an example for octal constant.
10 What is variable?
A variable is a data name that may be used to store a data value. Unlike the
constants that remain unchanged during the execution of a program, a
variable may take different values at different times during execution.
11 Mention the data types in C.
An expression such as a<b or 1<20 containing a relational operator (>, <, ==,!=,
<=,>=) is termed as Relational expression.
16 What is a logical expression?
An expression such as a>b && x==10, which combines two or more relational
expressions using logical operators (&&,||,!) is termed as Logical expression.
17 Mention the conversion types in C.
printf()
scanf()
getchar(), getch().
It is used for skipping a part of a loop. The continue statement tells the
compiler, “SKIP THE FOLLOWING STATEMENTS AND CONTINUE WITH THE NEXT
ITERATION”
28 What the difference is between break and exit statements?
break statement is used in switch statement to come out of the switch and the
program continues with the statement immediately following the switch
statement. Also when a break statement is encountered inside a loop, the
loop is immediately exited and the program continues with the statement
immediately following the loop.
exit statement is used to terminate the program forcibly when an error
condition is encountered. It is used when breaking out of a program is
necessary.
29 Define type conversion.
When we want to force a type conversion for example, ratio=(float) a/b; the
operator (float) converts a to floating point for the purpose of evaluation of
the expression. The process of such a local conversion is known as explicit
conversion or type casting.
31 Name the data structure used to store similar data.
Arrays
32 What is subscript?
Yes
Elements of the array can be accesses using array name along with the
index/subscript.
Ex: Num[0] , Num[1] ..
35 Mention the types of arrays.
type variable-name[size];
int Num[5];
38 Give an example to initialize one dimensional array.
int i;
float x[5]={1,2,3,4,5};
float total=0.0;
for(i=0;i<5;i++)
total =total + x[i] * x[i];
printf(“Average of sum of squares=%f”,total/5);
40 How to access the first element of an array?
Arrayname[0]
Searching is easier with sorted array, which takes less time to traverse array.
There are certain situations where a table of values will have to be stored. C
allows us to define such table using two dimensional arrays, To store tabulated
data into rows and columns.
43 Write the syntax to declare two dimensional array.
int a[10][10];
48 Define string.
Null Character(‘\0’)
char city[10];
#include<string.h>
strlen() function.
56 Write the string function to concatenate the two strings –“C V” “ RAMAN”.
str1=”C V”;
str2=”RAMAN”;
strcat(str1,str2); or strcat(“CV”,”RAMAN”);
57 How do you compare two strings?
The strcmp() function compares two strings identified by the arguments and
has a value 0 if they are equal.
58 What is the advantage of using a function in programming?
They are much easier to understand, debug and test. Also saves both time
and space.
59 Mention any one library function.
printf()
User defined function has to be developed by the user at the time of writing a
program. They are much easier to understand, debug and test.
61 Which are the types of functions?
The return_type_specifier tells the compiler what type of value that the
function is expected to return to the program calling the function.
63 Mention any two uses of using functions.
Variables that are both alive and active throughout the entire program are
known as external variables. They are also known as global variables.
73 Compare array with structure.
struct tag_name
{
data_type member1; //Structure definition
data_type member2;
………….
}; struct tag_name variable_list; //declaring structure variables
75 Declare the employee information using structure.
struct employee
{
char name[10];
int day;
char month[10];
int year;
float salary;
};
struct employee emp[10]; //array of structure
76 How to access an element of a structure?
struct st_record
{
int weight;
float height;
} student1; // declaring structure variable along with definition of
structure
struct st_record
{
int weight;
float height;
};
struct st_record student1={60, 180.75};
79 What is a nested structure?
Unions are a concept borrowed from structures and therefore follow the same
syntax as structures. But in unions all the members use the same storage
location. This implies that, although a union may contain many members of
different types, it can handle only one member at a time.
81 Compare union with structure.
The main advantage of typedef is that we can create meaningful data type
names for increasing the readability of the program.
83 Define a pointer.
int *p;
data_type * pointer_name;
float *fp;
90 What is call-by-value?
FILE *fp;
fp=fopen(“filename”,”mode”);
93 Mention any two mode parameters of the function fopen().
fclose(fp);
feof() is a status- inquiry library function. It helps in detecting I/O errors in the
files.
96 Mention any one function used in performing format based file operation.
fprintf(), fscanf();
A list of items of similar kind can be given one variable name using only one
subscript and such a variable is called a single- subscripted variable or a one-
dimensional array.
100 What is a string?
FILE *fp;
fp=fopen(“filename”,”mode”);
105 What is the length of the string “PU College”?
10
data_type arrayname[size];
The functions often called modules are self-contained small programs that
carry out some specific, well defined tasks.
110 What is structure?
No .
& is address operator, which returns the address of memory location of the
variable.
115 What character does represent the end of each string?
Null character.