0
Alien head

Programming in C

Description: A test for C programming. From beginner to expert
Number of Questions: 25
Created by:
Tags: Programming C C Plus Plus C Questions C Practice BBA / BBS / BCA Java/Oracle /C/C++
Attempted 0/25 Correct 0 Score 0

Which of the following functions will produce a value 10 if x = 9.7?

  1. log

  2. floor

  3. abs

  4. ceil

  5. round


Correct Option: D
Explanation:

The ceil function returns the smallest integral value greater than or equal to x. The result will be 10.000.

What will be the output of the above code?

for (;;) {
  printf("Hello");
}
  1. Compilation Error.

  2. The word 'Hello' will be printed infinitely.

  3. 'Hello' will be printed only once.

  4. 'Hello' will not be printed at all.

  5. 'Hello' will print once and then program will show a runtime error.


Correct Option: B
Explanation:

The C for statement has the following form:

for(start;condition;increment/decrement)   {}

In the statement given above since, nothing has been specified the for loop, it  will run infinitely. To terminate such a loop the 'ctrl+break' key combination should be pressed.

Which of the following symbols is used to denote passing of arguments 'by reference'?

  1. *

  2. &

  3. %

  4. !

  5. #


Correct Option: B
Explanation:

The call by reference method of passing arguments to a function copies the reference of an argument into the formal parameter. Inside the function, the reference is used to access the actual argument used in the call. This means that changes made to the parameter affect the passed argument. The ampersand(&) sign is used to denote pass by reference.

Which of the following is NOT a valid statement regarding recursive functions?

  1. A recursive function is a special function that calls itself.

  2. A recursive function allows us to break down a complex problem in small parts.

  3. It must have an exit condition.

  4. The first function call should be the first one to complete.

  5. Recursion method is applied in many algorithms such as quick sort or binary sort.


Correct Option: D
Explanation:

One of the properties of recursive functions is that a given function call must wait for the following function calls to complete its run before it itself can finish. The innermost function call must be completed before we can finish the next inner function call. We must make sure that the first function call (the outermost one) will be the last one to complete.

Which of the following functions is used to place the pointer at a particular position in a file?

  1. seekp()

  2. rewind()

  3. ftell()

  4. fseek()

  5. fread()


Correct Option: D
Explanation:

The fseek() is used to move the pointer at any position in a file. It is used in programs where we want to read or write data from/to a specific position in a file. It has the following syntax -
fseek(filepointer,int bytes,int offset)
where
file pointer is a pointer pointing to a file.
bytes - is the number of bytes that we want to move.
offset - denotes the position from where we want to move.for example 
fseek(fp,10,0)
will move the pointer 10 bytes from the beginning.

Which of the following statements is FALSE regarding functions in C?

  1. A function cannot return more than 1 value.

  2. It is a group of statements that performs a task.

  3. Functions cannot be defined by the user.

  4. The return statement is used to return a value from a function.

  5. A function can call any number of functions.


Correct Option: C
Explanation:

Although most of the programs can be made using inbuilt functions like printf(), scanf(), the user has the option of declaring his own functions. Such functions are known as user defined functions. The main objective of a user defined function is to save time and effort since,  a method can be called as many times as required.

What are tokens in C?

void main() {
  int const* p = 5;
  printf("%d", ++(*p));
}
  1. Collection of values having same data type

  2. The basic element recognized by the compiler

  3. The largest individual units of program

  4. Pointers

  5. References


Correct Option: B
Explanation:

Tokens are individual words and punctuation marks in passage of text. In C, program the smallest individual units are known as C Tokens. C has Six types of Tokens - Keywords,  Strings, Identifiers, Operators, Constants and special symbols.

What will the output of the strcmp() function if the strings to be compared are exactly the same?

  1. 0

  2. 1

  3. True

  4. False

  5. -1


Correct Option: A
Explanation:

The strcmp function compares the contents of two strings and returns a value indicating whether they are same or not. It can return the following values :
< 0 - If string1 is less than string2
> 0  - If  string2 is less than string1  
0    -   If string1 is equal to string2
Strcmp considers the case of the string during comparison.

When we declare a pointer to a structure, which of the following operators is used to access the structure variable through the pointer object?

  1. .(dot)

  2. * (Asterisk)

  3. & (Ampersand)

  4. -> (Arrow)

  5. # (Hash)


Correct Option: D
Explanation:

The -> (arrow) operator is used to reference individual members of a structures.The arrow operator is used with a pointer to an object. For example, if 'stud' is a pointer object pointing to a structure 'student', then the following statement can be used to access the member of the structure.
printf("%d",*s-&gt;rollno);

Which of the following statements is FALSE regarding switch case statement?

  1. We can have any number of case statements within a switch.

  2. When a break statement is reached, the switch terminates.

  3. Using default in switch case is optional.

  4. The value to be compared can be of any type.

  5. Every case need not have a break statement.


Correct Option: D
Explanation:

The value to be compared should be of integral type. We cannot compare a floating point value using a switch-case.

Which of the following file modes opens the file in such a way that all the new data is added to the end of file and we can perform reading operations also?

  1. w

  2. a

  3. a+

  4. +a

  5. w+


Correct Option: C
Explanation:

The a+ mode opens a text file for reading and writing both. It creates the file if it does not exist. The reading will start from the beginning but writing can only be appended.

What is a Dequeue?

  1. It is the same as queue.

  2. Elements can be added from the top only.

  3. Elements can only be removed from the front and added from the rear.

  4. Elements can only be added from the front and removed from rear.

  5. Elements can be added to or removed from either the front or rear.


Correct Option: E
Explanation:

A dequeue (Double Ended Queue) is a data structure in which elements can be added or removed from the ends (front or rear). Elements of a deque can be scattered in different groups of storage, with the container keeping the necessary information internally to provide direct access to any of its elements in constant time and with a uniform sequential interface.

Which of the following keywords is used to change the name of an inbuilt datatype during compilation?

  1. #define

  2. rename

  3. typedef

  4. #pragma

  5. const


Correct Option: C
Explanation:

The typedef keyword can be used to give a new name to a data type. For example,
typedef int number;
The above statement will change the name of the 'int' type to 'number'. Therefore to declare an integer varaible we can also use the statement :
number age;

What is the use of the perror() function in C?

  1. Prints the error message specified by the compiler.

  2. Works same as printf().

  3. Prints the garbage value assigned by the compiler.

  4. Works same as the gets() method.

  5. None of the above


Correct Option: A
Explanation:

The C library function void perror(const char *str) prints a descriptive error message to stderr. First the string str is printed followed by a colon then a space. Syntax : void perror (const char *str) where str is the user defined message that prints before the actual error message.

Which of the following statements is FALSE regarding structures?

  1. Structures are user defined data types.

  2. Structures cannot be nested.

  3. Structures can contain different types of variables.

  4. Structures are used to represent a record.

  5. The dot operator is used to access the structure members.


Correct Option: B
Explanation:

Structures can be nested. A structure can contain a reference of another structure. For example :
struct person
{
  char name[10]:
  int age;
};
struct emp
{
int empno;
personal person;
};

In the above code the 'person' variable has a reference of the 'person' structure as its datatype. If an object of the structure 'emp' is declared, we can not only access the member of 'emp' but also of the 'person' structure.

Which of the following is NOT an operator in C?

  1. sizeof

  2. !

  3. ~

  4. | |

  5. scope resoultion operator (: :)


Correct Option: E
Explanation:

The scope resoultion operator is not a valid C operator. It is used in C++ to specify the scope of a variable or object.

void main() {
  int i = 4, x;
  x = ++i + ++i + ++i;
  printf("%d", x);
}

What will be the output of the above code?

  1. 20

  2. 21

  3. 18

  4. 19

  5. 22


Correct Option: B
Explanation:

The ++ operator is the pre fix increment operator. The pre increment operator first increments the variable up to break point then starts assigning the final value to all variable. Therefore the statement
x=++i + ++i + ++i;
will translate into
x=5+6+7;
after all the increments are finished, x will have the value 7 since, that is the last value after the statement. Now the final result will be
x=7+7+7
that is 21.

Which of the following data structures stores the data in FIFO mode?

  1. LinkedList

  2. Binary Tree

  3. Stack

  4. Queue

  5. Array


Correct Option: D
Explanation:

A queue is a data structure which stores the data in First In First Out Mode. A queue consists of two sides - front and rear. The nodes are added from the rear side and removed from the front side just like people join a queue from the end and pull out   from the beginning in a real life queue. The node that was added the first is also the first one to be removed.

Which of the following functions is used to release the allocated memory which is no longer required?

  1. dealloc()

  2. delete()

  3. free()

  4. realloc()

  5. clear()


Correct Option: C
Explanation:

When the program closes, operating system automatically releases all the memory allocated by the program but it a good programming practice to release that memory by calling the function free(). The free() function is defined in the header file malloc.h

Which of the following is NOT a valid sorting method?

  1. Insertion sort

  2. Selection sort

  3. Bubble sort

  4. Merge Sort

  5. Deep Sort


Correct Option: E
Explanation:

Deep sort is not a valid sort type.

Which of the following tree traversal methods have the order as - root , left, right?

  1. Preorder

  2. Linear

  3. Level Order

  4. Inorder

  5. Postorder


Correct Option: A
Explanation:

The preorder traversal of a tree reads the node in root, left, right order. The data of a node will be read first, if the node has a left child node it will be accessed next, followed by the right child node.

Which of the following format specifiers is used to process unsigned hexadecimal values?

  1. %x

  2. %d

  3. %o

  4. %u

  5. %e


Correct Option: A
Explanation:

The %x specifier is used to print int as hexadecimal values,' x' uses lower-case letters and 'X' uses upper-case.

int main() {
  float x = fun(2, 3);
  printf("%f", x);
}
int fun(int x, float y)  // Line 7
 {
    x = 20.9; //Line 9 
    return x; 
}

What will be the output of the above code?

  1. 20.99

  2. 20.00

  3. No output

  4. Error

  5. 20


Correct Option: D
Explanation:

In main function, definition of func() is not know to the compiler during compilation so it will assume the return type and parameter type to int,  but in definition when it sees the parameter type is float, it throws an error.

The default parameter passing mechanism is called __________.

  1. call by value

  2. call by name

  3. call by reference

  4. call by address

  5. call by default


Correct Option: A
Explanation:

The call by value method of passing arguments to a function copies the actual value of an argument into the formal parameter of the function. In this case, changes made to the parameter inside the function have no effect on the argument. By default, C uses call by value to pass arguments. In general, this means that code within a function cannot alter the arguments used to call the function. 

Which of the following statements is TRUE regarding the 'switch' statement?

  1. continue can be used but break cannot be used

  2. continue cannot be used but break can be used

  3. Both continue and break can be used

  4. Neither continue nor break can be used

  5. We cannot use switch statement in nested form


Correct Option: B
Explanation:

The break is used to break out of the case statements. Break is a keyword that breaks out of the code block, usually surrounded by braces, which it is in. In this case, break prevents the program from falling through and executing the code in all the other case statements. 

+ View questions