Questions
Questions
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.
It is referred to as a terminating null character, and is used primarily to show the end of a
string value.
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.
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.
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.
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.
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?
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.
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.
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.
while(0 == 0) {
}
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.
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].
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.
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]).
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.
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.
The strcat function. It takes two parameters, the source string and the string value to be
appended to the source string.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
void f() {
int i;
auto int j;
}
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.
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.
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.
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.
4.Which operator is used to continue the definition of macro in the next line?
Backward slash (\) is used.
Welcome to C"
5.Explain about ‘stdin’.
stdin in a pointer variable which is by default opened for standard input device.
8.How can we determine whether a file is successfully opened or not using fopen()
function?
On failure fopen() returns NULL, otherwise opened successfully.
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.
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.