Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
118 views

C Programming Questions and Answers 2

The document discusses various topics related to the C programming language including: - Two key features of C are that it is robust and programs written in C are efficient and fast. - The components of C language are the compiler, editor, and programmer. - Tokens are the smallest building blocks of a C program and include keywords and identifiers. - Common data types in C include int, char, float, double, and void. - Selection statements include if, else if, switch, and conditional operator statements. - Looping statements are for, while, and do while loops. - Functions allow code reusability and make programs easier to understand, debug, and

Uploaded by

Shakir Hussain
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
118 views

C Programming Questions and Answers 2

The document discusses various topics related to the C programming language including: - Two key features of C are that it is robust and programs written in C are efficient and fast. - The components of C language are the compiler, editor, and programmer. - Tokens are the smallest building blocks of a C program and include keywords and identifiers. - Common data types in C include int, char, float, double, and void. - Selection statements include if, else if, switch, and conditional operator statements. - Looping statements are for, while, and do while loops. - Functions allow code reusability and make programs easier to understand, debug, and

Uploaded by

Shakir Hussain
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 17

I M UMESH M Sc.

, M Phil
1 Mention any two features of C language.

 C is a robust language whose rich set of built-in functions and operators


can be used to write any complex program.
 Programs written in C are efficient and fast.
 C is highly portable and another important feature of C is its ability to
extend itself.
2 Mention the components of C language.

Compiler, Editor, Programmer.

3 What does a character represent?

The characters in C are grouped into the following categories.


 Letters A…Z and a…z
 Digits 0…9
 Special characters &,*,%,# +etc
 White Spaces \n \t
4 Is C case sensitive?

Yes C is case sensitive

5 What is a token?

Token is a smallest and basic building block of C program.

6 Mention any two tokens.

Keywords, Identifiers.

7 What are keywords?

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.

0123, 011, 071

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.

Primitive/Basic data types in C are: int, char, float, double, void

12 What does an expression contain?

An expression is a combination of variables, constants and operators arranged


as per the syntax of the language.
13 Mention the types of expressions in C.

Arithmetic Expression, Relational Expression, Logical Expression.

14 What is an arithmetic expression?

An arithmetic expression is a combination of variables, constants and


arithmetic operators (+,-,*,/,%) arranged as per the syntax of the language.
15 What is a relational expression?

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.

Implicit Type Conversion and Explicit Type Conversion.

18 Mention the output function used in C.

printf()

19 Mention the input function used in C.

scanf()

20 Write the format of printf( ) function.

printf(“control string”, arg1, arg2,…., argn);

21 Write the format of scanf( ) function.

scanf(“control string”, arg1, arg2,…., argn);

22 List character input functions.

getchar(), getch().

23 Which are the selection statements of C?

Simple if statement, if…else statement, nested if… else statement, else if


ladder, switch statement, conditional operator statement, goto statement.
24 What is the difference between if and switch statements?

if statement switch statement


Two way decision making statement Multiway decision making
statement
25 Mention the looping statements of C.

for statement, while statement, do while statement.

26 What is the purpose of break statement?

When a break statement is encountered in a switch statement, it takes the


control out of switch statement to the statement immediately following the
switch block.
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.
27 What is the purpose of continue statement?

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.

C permits mixing of constants and variables of different data types in an


expression. During evaluation the ‘lower’ type is automatically converted to
the ‘higher’ type. This automatic conversion is known as implicit type
conversion.
Ex: int a=2; float b,c=3.2; b=a+c; Here a is automatically converted to float
and result will be in float.
30 Define type casting.

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?

In an array the subscript refers to the index or position of the element in an


array.
Ex: int Num[5]; //* declaring array Num with size 5 i.e 5 slots, each slot will be
numbered starting from 0*//
Num[0]
Num[1]
Num[2]
Num[3]
Num[4]

Num[1]=20; here //* accessing second slot of array Num with


index/subscript 1 as the subscript of array starts from 0 always*//
33 Can the subscript of an array variable be zero?

Yes

34 How can the element in array be accessed?

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.

One dimensional Array, Two dimensional Array, Multi dimensional Array.

36 What is one-dimensional array?


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.
37 Write the syntax to declare an array to store 5 elements.

type variable-name[size];
int Num[5];
38 Give an example to initialize one dimensional array.

type variable-name[size]= { list of values};


int Num[5]={1,3,5,7,9}; //*Compile time initialization*//
for(i=0;i<5;i++) //*Run time initialization*//
{
Num[i]=i;
}
39 Write the program segment to access an element from an 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]

41 What is the advantage of sorted array?

Searching is easier with sorted array, which takes less time to traverse array.

42 What is two dimensional 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.

Two dimensional arrays are declared as follows:


type array_name [row_size][column_size];
44 Give an example to declare two dimensional array.

int a[10][10];

45 Write the statement to initialize the 2 X 2 matrix.

int a[2][2]={{1,1},{2,2}); or int a[2][2]={1,1,2,2};

46 Write the syntax to declare multi-dimensional array.

type array_name[s1][s2][s3]….[sm]; where si is the size of the ith dimension.

47 To access the first character, what should be the index?

Index should be zero.

48 Define string.

A string is a sequence of characters that is treated as a single data item.

49 Which is the character that indicates the end of string?

Null Character(‘\0’)

50 Write an example to declare string variable.

char city[10];

51 Which header file is compulsory for string manipulations?

#include<string.h>

52 What is the syntax of puts () function?

puts(str); where str is a string variable containing a string value.


53 Write an example to print the string using printf() function.

printf(“%s”,name); can be used to display the entire contents of the array


name.
54 Which function is used to count the number of characters in a string?

strlen() function.

55 Write the syntax of strcpy() function.

strcpy(string1,string2); assigns the contents of string2 to string1

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()

60 What is user defined functions?

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?

 Functions with no arguments and no return values.


 Functions with arguments and no return values.
 Functions with arguments and one return value.
 Functions with no arguments but return a value.
 Functions that return multiple values.
62 What does return_type_specifier indicate in function declaration?

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.

The length of the program can be reduced by using functions at appropriate


places.
It is easy to locate and isolate a faulty function i.e debugging is easy.
64 Write the syntax for calling the function.

function_name(arg1,arg2…argn); ex: mul(10,5);


Where arg1, arg2… argn are actual parameters.
65 What value does the following statement return?
return(x);
It returns the value of x to the calling function.

66 What are different types of parameters used in functions?

Actual Parameters and Formal Parameters.

67 What is the difference between local and global variable?

A Local variable defined inside a function is known only to that function. It is


destroyed when the function is exited.
A global variable is visible from the point of its declaration (which is placed
above all the functions) to the end of the program. A global variable used in a
function will retain its value for future use.
68 Write the syntax of function prototype.

function_type function_name (parameter list);


69 Define recursion.

When a called function in turn calls another function a process of chaining


occurs. Recursion is a special case of this process, where a function calls itself.
70 Mention any two storage classes.

Automatic, External, Static, Register.

71 What is automatic variable?

Automatic variables are declared inside a function in which they are to be


utilized. They are created when the function is called and destroyed
automatically when the function is exited.
72 What is external variable?

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.

An Array is a fixed-size sequenced collection of elements of same data type.


Structure is a constructed datatype for packing data of different data types.
74 Write the syntax to declare a 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?

We can access and assign values to the members/elements of a structure


using member operator ‘.’ Which is also known as dot or period operator.
Ex: book1.price where book1 is structure variable and price is the element of
structure
77 Write the statement to accept the value for a structure member.

struct st_record
{
int weight;
float height;
} student1; // declaring structure variable along with definition of
structure

scanf(“%d %f”,&student1.height,&student1.weight); //run-time


initialization
78 Write an example to initialize the structure with two members.

struct st_record
{
int weight;
float height;
};
struct st_record student1={60, 180.75};
79 What is a nested structure?

A structure within a structure means nesting of structures. That is member of a


structure will be itself a structure.
80 What is union?

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.

Major distinction between structures and unions is in terms of storage.


In structures, each member has its own storage location; where as all the
members of a union shares the same location. The compiler allocates a piece
of storage that is large enough to hold the largest variable type in the union.
82 What is the use of typedef data type?

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.

A Pointer is a derived datatype in C. Pointers contain memory addresses as


their values.
84 Give an example to declare pointer variable.

int *p;

85 What is the syntax to declare a pointer?

data_type * pointer_name;

86 Which is the pointer operator?

* pointer operator(indirection operator), & address operator


87 Which is address operator?

& address operator

88 Declare float type pointer variable.

float *fp;

89 Write any one valid pointer arithmetic expression.

Y=*p1 + *p2 / *p1;

90 What is call-by-value?

The process of passing the actual value of variables is known as “call by


value”.
91 What is a file?

A file is a place on the disk where a group of related data is stored.

92 Write the syntax to open a file.

FILE *fp;
fp=fopen(“filename”,”mode”);
93 Mention any two mode parameters of the function fopen().

r ->open the file for reading only


w ->open the file for writing only
a ->open the file for appending data to it
94 Which function is used to close the file?

fclose(fp);

95 What is the use of feof() function?

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();

97 Write the syntax of fread() function.

fscanf(fp, “control string”, variable_list);

98 Write the syntax of fputs() function.

fputs(str,fp); where str is a string and fp is a file pointer

99 Define one dimensional array.

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?

A string is a sequence of characters that is treated as a single data item.

101 What is the significance of NULL character?

Null character serves as the “end –of-string” marker.

102 How is function invoked?

Function is invoked through function call.

103 What is a function prototype?


Like variables, all functions in C program must be declared, before they are
invoked. A function declaration is also known as function prototype.
104 How do we declare a file?

FILE *fp;
fp=fopen(“filename”,”mode”);
105 What is the length of the string “PU College”?

10

106 What is recursion?


When a called function in turn calls another function a process of chaining
occurs. Recursion is a special case of this process, where a function calls itself.
107 Write the syntax for one-dimensional array declaration.

data_type arrayname[size];

108 What is recursive function?

Function calling itself is known as recursive function.

109 What is pointer?

A Pointer is a derived datatype in C. Pointers contain memory addresses as


their values.
110 What is function?

The functions often called modules are self-contained small programs that
carry out some specific, well defined tasks.
110 What is structure?

Structure is a constructed datatype for packing data of different data types.

111 Can array store more than one type of variable?

No .

112 Define recursion.

When a called function in turn calls another function a process of chaining


occurs. Recursion is a special case of this process, where a function calls itself.
113 Give one characteristic of the subscript of an array.

Subscript is the position of an element in the array. Subscript of array is always


an integer.
114 What is the significance of & operator in pointers?

& 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.

116 What is the main difference between structure & union?

Major distinction between structures and unions is in terms of storage.


In structures, each member has its own storage location; where as all the
members of a union shares the same location. The compiler allocates a piece
of storage that is large enough to hold the largest variable type in the union.

You might also like