0% found this document useful (0 votes)
112 views

Questions

The document discusses various concepts in C programming. It defines tokens, format specifiers, null characters, relational and assignment operators, modulus operator, syntax errors, variables vs constants, arrays, loops, pointers, strings and comments. Key differences explained are between compilers and interpreters, logical vs syntax errors, prefix and postfix increment, and infinite vs endless loops. The document also discusses header files, algorithms, debugging, compound statements and advantages of arrays over individual variables.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
112 views

Questions

The document discusses various concepts in C programming. It defines tokens, format specifiers, null characters, relational and assignment operators, modulus operator, syntax errors, variables vs constants, arrays, loops, pointers, strings and comments. Key differences explained are between compilers and interpreters, logical vs syntax errors, prefix and postfix increment, and infinite vs endless loops. The document also discusses header files, algorithms, debugging, compound statements and advantages of arrays over individual variables.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 12

UNIT-I

1.What is a token?
A C program consists of various tokens and a token is either a keyword, an identifier, a
constant, a string literal, or a symbol.

2. Explain the use of %i format specifier w.r.t scanf().

Can be used to input integer in all the supported format.

3. What is the use of a ‘’ character?

It is referred to as a terminating null character, and is used primarily to show the end of a
string value.

4.What is the difference between the = symbol and == symbol?

The = symbol is often used in mathematical operations. It is used to assign a value to a


given variable. On the other hand, the == symbol, also known as “equal to” or “equivalent to”, is
a relational operator that is used to compare two values.

5. What is the modulus operator?

The modulus operator outputs the remainder of a division. It makes use of the percentage
(%) symbol. For example: 10 % 3 = 1, meaning when you divide 10 by 3, the remainder is 1.

6. Which of the following operators is incorrect and why? ( >=, <=, <>, ==)

<> is incorrect. While this operator is correctly interpreted as “not equal to” in writing
conditional statements, it is not the proper operator to be used in C programming. Instead, the
operator != must be used to indicate “not equal to” condition.

7.Compare and contrast compilers from interpreters.

Compilers and interpreters often deal with how program codes are executed. Interpreters
execute program codes one line at a time, while compilers take the program as a whole and
convert it into object code, before executing it. The key difference here is that in the case of
interpreters, a program may encounter syntax errors in the middle of execution, and will stop
from there. On the other hand, compilers check the syntax of the entire program and will only
proceed to execution when no syntax errors are found.

8. What are header files and what are its uses in C programming?
Header files are also known as library files. They contain two essential things: the
definitions and prototypes of functions being used in a program. Simply put, commands that you
use in C programming are actually functions that are defined from within each header files. Each
header file contains a set of functions. For example: stdio.h is a header file that contains
definition and prototypes of commands like printf and scanf.
9.What is syntax error?

Syntax errors are associated with mistakes in the use of a programming language. It
maybe a command that was misspelled or a command that must was entered in lowercase mode
but was instead entered with an upper case character. A misplaced symbol, or lack of symbol,
somewhere within a line of code can also lead to syntax error.

10.What are variables and it what way is it different from constants?


Variables and constants may at first look similar in a sense that both are identifiers made
up of one character or more characters (letters, numbers and a few allowable symbols). Both will
also hold a particular value. Values held by a variable can be altered throughout the program,
and can be used in most operations and computations. Constants are given values at one time
only, placed at the beginning of a program. This value is not altered in the program. For
example, you can assigned a constant named PI and give it a value 3.1415 . You can then use it
as PI in the program, instead of having to write 3.1415 each time you need it.
11. Can the curly brackets { } be used to enclose a single line of code?
While curly brackets are mainly used to group several lines of codes, it will still work
without error if you used it for a single line. Some programmers prefer this method as a way of
organizing codes to make it look clearer, especially in conditional statements.
12. What is the significance of an algorithm to C programming?

Before a program can be written, an algorithm has to be created first. An algorithm


provides a step by step procedure on how a solution can be derived. It also acts as a blueprint on
how a program will start and end, including what process and computations are involved.

13. What is wrong in this statement? scanf(“%d”,whatnumber);

An ampersand & symbol must be placed before the variable name whatnumber. Placing
& means whatever integer value is entered by the user is stored at the “address” of the variable
name. This is a common mistake for programmers, often leading to logical errors.

14.How do you generate random numbers in C?

Random numbers are generated in C using the rand() command. For example: anyNum =
rand() will generate any integer number beginning from 0, assuming that anyNum is a variable of
type integer.

15.What are comments and how do you insert it in a C program?

Comments are a great way to put some remarks or description in a program. It can serves
as a reminder on what the program is all about, or a description on why a certain code or function
was placed there in the first place. Comments begin with /* and ended by */ characters.
Comments can be a single line, or can even span several lines. It can be placed anywhere in the
program.

16.What is debugging?

Debugging is the process of identifying errors within a program. During program


compilation, errors that are found will stop the program from executing completely. At this state,
the programmer would look into the possible portions where the error occurred. Debugging
ensures the removal of errors, and plays an important role in ensuring that the expected program
output is met.

17.What does the && operator do in a program code?

The && is also referred to as AND operator. When using this operator, all conditions
specified must be TRUE before the next action can be performed. If you have 10 conditions and
all but 1 fails to evaluate as TRUE, the entire condition statement is already evaluated as FALSE.

18.What are logical errors and how does it differ from syntax errors?

Program that contains logical errors tend to pass the compilation process, but the
resulting output may not be the expected one. This happens when a wrong formula was inserted
into the code, or a wrong sequence of commands was performed. Syntax errors, on the other
hand, deal with incorrect commands that are misspelled or not recognized by the compiler.

19.What is the difference between the expression “++a” and “a++”?

In the first expression, the increment would happen first on variable a, and the resulting
value will be the one to be used. This is also known as a prefix increment. In the second
expression, the current value of variable a would the one to be used in an operation, before the
value of a itself is incremented. This is also known as postfix increment.

20.What would happen to X in this expression: X += 15; (assuming the value of X is 5)

X +=15 is a short method of writing X = X + 15, so if the initial value of X is 5, then 5 +


15 = 20.

21.What is an endless loop?

An endless loop can mean two things. One is that it was designed to loop continuously
until the condition within the loop is met, after which a break function would cause the program
to step out of the loop. Another idea of an endless loop is when an incorrect loop condition was
written, causing the loop to run erroneously forever. Endless loops are oftentimes referred to as
infinite loops.
UNIT-II
1.What is a nested loop?

A nested loop is a loop that runs within another loop. Put it in another sense, you have an
inner loop that is inside an outer loop. In this scenario, the inner loop is performed a number of
times as specified by the outer loop. For each turn on the outer loop, the inner loop is first
performed.

2.What is a constant pointer?


A pointer which is not allowed to be altered to hold another address after it is holding
one.

3.What are valid operations on pointers?


The only two permitted operations on pointers are

 Comparision ii) Addition/Substraction (excluding void pointers)


4.What is a string length?
It is the count of character excluding the ‘\0’ character.

5.What is an infinite loop?


A loop executing repeatedly as the loop-expression always evaluates to true such as

while(0 == 0) {
}

6.How do you declare a variable that will hold string values?

The char keyword can only hold 1 character value at a time. By creating an array of
characters, you can store string values in it. Example: “char MyName[50]; ” declares a string
variable named MyName that can hold a maximum of 50 characters.

7.How do you access the values within an array?

Arrays contain a number of elements, depending on the size you gave it during variable
declaration. Each element is assigned a number from 0 to number of elements-1. To assign or
retrieve the value of a particular element, refer to the element number. For example: if you have
a declaration that says “intscores[5];”, then you have 5 accessible elements, namely: scores[0],
scores[1], scores[2], scores[3] and scores[4].

8.What are compound statements?

Compound statements are made up of two or more program statements that are executed
together. This usually occurs while handling conditions wherein a series of statements are
executed when a TRUE or FALSE is evaluated. Compound statements can also be executed
within a loop. Curly brackets { } are placed before and after compound statements.

9.What is the advantage of an array over individual variables?

When storing multiple related data, it is a good idea to use arrays. This is because arrays
are named using only 1 word followed by an element number. For example: to store the 10 test
results of 1 student, one can use 10 different variable names (grade1, grade2, grade3… grade10).
With arrays, only 1 name is used, the rest are accessible through the index name (grade[0],
grade[1], grade[2]… grade[9]).

10. Can the “if” function be used in comparing strings?

No. “if” command can only be used to compare numerical values and single character
values. For comparing string values, there is another function called strcmp that deals
specifically with strings.

11.How do you determine the length of a string value that was stored in a variable?

To get the length of a string value, use the function strlen(). For example, if you have a
variable named FullName, you can get the length of the stored string value by using this
statement: I = strlen(FullName); the variable I will now have the character length of the string
value.

12.When is a “switch” statement preferable over an “if” statement?

The switch statement is best used when dealing with selections based on a single variable
or expression. However, switch statements can only evaluate integer and character data types.

13.What are multidimensional arrays?

Multidimensional arrays are capable of storing data in a two or more dimensional


structure. For example, you can use a 2 dimensional array to store the current position of pieces
in a chess game, or position of players in a tic-tac-toe program.

14.Which function in C can be used to append a string to another string?

The strcat function. It takes two parameters, the source string and the string value to be
appended to the source string.

15.In a switch statement, what will happen if a break statement is omitted?

If a break statement was not placed at the end of a particular case portion? It will move
on to the next case portion, possibly causing incorrect output.
UNIT-III
1.What are formal parameters?

In using functions in a C program, formal parameters contain the values that were passed
by the calling function. The values are substituted in these formal parameters and used in
whatever operations as indicated within the main body of the called function.

2. What are actual arguments?

When you create and use functions that need to perform an action on some given values,
you need to pass these given values to that function. The values that are being passed into the
called function are referred to as actual arguments.

3. What is the difference between functions getch() and getche()?

Both functions will accept a character input value from the user. When using getch(), the
key that was pressed will not appear on the screen, and is automatically captured and assigned to
a variable. When using getche(), the key that was pressed by the user will appear on the screen,
while at the same time being assigned to a variable.

4.What is a NULL pointer?


A pointer pointing to nothing is called so. Eg: char *p=NULL;

5.When to user -> (arrow) operator.


If the structure/union variable is a pointer variable, to access structure/union elements the
arrow operator is used.

6.What are bit fields?


We can create integer structure members of differing size apart from non-standard size
using bit fields. Such structure size is automatically adjusted with the multiple of integer size of
the machine.

7. What are global variables and how do you declare them?

Global variables are variables that can be accessed and manipulated anywhere in the
program. To make a variable global, place the variable declaration on the upper portion of the
program, just after the preprocessor directives section.

8. Is it possible to have a function as a parameter in another function?

Yes, that is allowed in C programming. You just need to include the entire function
prototype into the parameter field of the other function where it is to be used.

9. What is dynamic data structure?


Dynamic data structure provides a means for storing data more efficiently into memory.
Using dynamic memory allocation, your program will access memory spaces as needed. This is
in contrast to static data structure, wherein the programmer has to indicate a fix number of
memory space to be used in the program.

10. Describe how arrays can be passed to a user defined function

One thing to note is that you cannot pass the entire array to a function. Instead, you pass
to it a pointer that will point to the array first element in memory. To do this, you indicate the
name of the array without the brackets.

11. What are pointers?

Pointers point to specific areas in the memory. Pointers contain the address of a variable,
which in turn may contain a value or even an address to another memory.

12. What is gets() function?

The gets() function allows a full line data entry from the user. When the user presses the
enter key to end the input, the entire line of characters is stored to a string variable. Note that the
enter key is not included in the variable, but instead a null terminator is placed after the last
character.

13.What is the difference between Call by Value and Call by Reference?

When using Call by Value, you are sending the value of a variable as parameter to a
function, whereas Call by Reference sends the address of the variable. Also, under Call by
Value, the value in the parameter is not affected by whatever operation that takes place, while in
the case of Call by Reference, values can be affected by the process within the function.

14.What is a pointer on pointer?


It’s a pointer variable which can hold the address of another pointer variable. It de-refers
twice to point to the data held by the designated pointer variable.

Eg: int x = 5, *p=&x, **q=&p;

Therefore ‘x’ can be accessed by **q.


UNIT-IV
1.Distinguish between malloc() & calloc() memory allocation.
Both allocates memory from heap area/dynamic memory. By default calloc fills the
allocated memory with 0’s.

2.What is recursion?
Function calling itself is called as recursion.

3.What is typecasting?
Typecasting is a way to convert a variable/constant from one type to another type.

4.Define a structure.

A structure can be defined of collection of heterogeneous data items

5.What are enumerated types?

Enumerated types allow the programmer to use more meaningful words as values to a
variable. Each item in the enumerated type variable is actually associated with a numeric code.
For example, one can create an enumerated type variable named DAYS whose values are
Monday, Tuesday… Sunday.

6.Distinguish between malloc() & calloc() memory allocation.


Both allocates memory from heap area/dynamic memory. By default calloc fills the
allocated memory with 0’s.

7.What is keyword auto for?


By default every local variable of the function is automatic (auto). In the below function
both the variables ‘i’ and ‘j’ are automatic variables.

void f() {
int i;
auto int j;
}

NOTE − A global variable can’t be an automatic variable.

8.What are preprocessor directives?

Preprocessor directives are placed at the beginning of every C program. This is where
library files are specified, which would depend on what functions are to be used in the program.
Another use of preprocessor directives is the declaration of constants.Preprocessor directives
begin with the # symbol.

9.What are enumerations?


Enumerations are list of integer constants with name. Enumerators are defined with the
keyword enum.

10.What are the different ways of passing parameters to the functions? Which to use
when?
 Call by value − We send only values to the function as parameters. We choose this if we
do not want the actual parameters to be modified with formal parameters but just used.

 Call by reference − We send address of the actual parameters instead of values. We


choose this if we do want the actual parameters to be modified with formal parameters.

11.What are command line arguments?


The arguments which we pass to the main() function while executing the program are
called as command line arguments. The parameters are always strings held in the second
argument (below in args) of the function which is array of character pointers. First argument
represents the count of arguments (below in count) and updated automatically by operating
system.

main( int count, char *args[]) {


}

12.When to user -> (arrow) operator.


If the structure/union variable is a pointer variable, to access structure/union elements the
arrow operator is used.

13.What are bit fields?


We can create integer structure members of differing size apart from non-standard size
using bit fields. Such structure size is automatically adjusted with the multiple of integer size of
the machine.

14.When should we use the register storage specifier?


If a variable is used most frequently then it should be declared using register storage
specifier, then possibly the compiler gives CPU register for its storage to speed up the look up
of the variable.

15.Where an automatic variable is stored?

Every local variable by default being an auto variable is stored in stack memory.
16.What is a nested structure?
A structure containing an element of another structure as its member is referred so.

17.What is a self-referential structure?


A structure containing the same structure pointer variable as its element is called as self-
referential structure.

18.What is a static variable?


A static local variables retains its value between the function call and the default value is
0. The following function will print 1 2 3 if called thrice.

void f() {
static int i;
++i;
printf(“%d “,i);
}

If a global variable is static then its visibility is limited to the same source code.
UNIT-V

1.What is a preprocessor?
Preprocessor is a directive to the compiler to perform certain things before the actual
compilation process begins.

2.What is difference between including the header file with-in angular braces < > and
double quotes “ “
If a header file is included with in < > then the compiler searches for the particular
header file only with in the built in include path. If a header file is included with in “ “, then the
compiler searches for the particular header file first in the current working directory, if not
found then in the built in include path.

3.Describe the file opening mode “w+”.


Opens a file both for reading and writing. If a file is not existing it creates one, else if the
file is existing it will be over written.

4.Which operator is used to continue the definition of macro in the next line?
Backward slash (\) is used.

E.g. #define MESSAGE "Hi, \

Welcome to C"
5.Explain about ‘stdin’.
stdin in a pointer variable which is by default opened for standard input device.

6.Name a function which can be used to close the file stream.


fclose().

7.What is the purpose of #undef preprocessor?


It be used to undefine an existing macro definition.

8.How can we determine whether a file is successfully opened or not using fopen()
function?
On failure fopen() returns NULL, otherwise opened successfully.

9.When the macros gets expanded?


At the time of preprocessing.

10.What is a sequential access file?


When writing programs that will store and retrieve data in a file, it is possible to
designate that file into different forms. A sequential access file is such that data are saved in
sequential order: one data is placed into the file after another. To access a particular data within
the sequential access file, data has to be read one data at a time, until the right one is reached.

11.What is the difference between functions getch() and getche()?

Both functions will accept a character input value from the user. When using getch(), the
key that was pressed will not appear on the screen, and is automatically captured and assigned to
a variable. When using getche(), the key that was pressed by the user will appear on the screen,
while at the same time being assigned to a variable.

12.What does the characters “r” and “w” mean when writing programs that will make use
of files?

“r” means “read” and will open a file as input wherein data is to be retrieved. “w” means
“write”, and will open a file for output. Previous data that was stored on that file will be erased.

13.What is the advantage of a random access file?

If the amount of data stored in a file is fairly large, the use of random access will allow
you to search through it quicker. If it had been a sequential access file, you would have to go
through one record at a time until you reach the target data. A random access file lets you jump
directly to the target address where data is located.

14.How do you search data in a data file using random access method?

Use the fseek() function to perform random access input/ouput on a file. After the file
was opened by the fopen() function, the fseek would require three parameters to work: a file
pointer to the file, the number of bytes to search, and the point of origin in the file.

You might also like