Prepare Interview

Mock Exams

Make Homepage

Bookmark this page

Subscribe Email Address

Language in C Interview Questions and Answers

Test your skills through the online practice test: Language in C Quiz Online Practice Test

Ques 61. How do I use swab( ) in my program ?

The function swab( ) swaps the adjacent bytes of memory. It copies the bytes from source string to the target string, provided that the number of characters in the source string is even. While copying, it swaps the bytes which are then assigned to the target string.

#include <stdlib.h>
#include <stdio.h>
#include <string.h>

main ( )
{
char *str1 = "hS eesll snsiasl not eh es as oher " ;
char *str2 ;
clrscr( ) ;
swab ( str1, str2, strlen ( str1 ) ) ;
printf ( "The target string is : %sn", str2 ) ; // output -- She sells
snails on the sea shore
getch( ) ;
}

Is it helpful? Add Comment View Comments
 

Ques 62. What does the error "Null Pointer Assignment" mean and what causes this error?

The Null Pointer Assignment error is generated only in small and medium memory models. This error occurs in programs which attempt to change the bottom of the data segment. In Borland's C or C++ compilers, Borland places four zero bytes at the bottom of the data segment, followed by the Borland copyright notice "Borland C++ - Copyright 1991 Borland Intl.". In the small and medium memory models, a null pointer points to DS:0000. Thus assigning a value to the memory referenced by this pointer will overwrite the first zero byte in the data segment. At program termination, the four zeros and the copyright banner are checked. If either has been modified, then the Null Pointer Assignment error is generated. Note that the pointer may not truly be null, but may be a wild pointer that references these key areas in the data segment.

Data Structures

Is it helpful? Add Comment View Comments
 

Ques 63. How to build an expression trees ?

An expression tree is a binary tree which is built from simple operands and operators of an (arithmetic or logical ) expression by placing simple operands as the leaves of a binary tree and the operators as the interior nodes. If an operator is binary , then it has two nonempty subtrees, that are its left and right operands (either simple operands or sub expressions). If an operator is unary, then only one of its subtrees is nonempty, the one on the left or right according as the operator is written on the right or left of its operand. We traditionally write some unary operators to the left of their operands, such as "-" ( unary negation) or the standard functions like log( ), sin( ) etc. Others are written on the right, such as the factorial function ()!. If the operator is written on the left, then in the expression tree we take its left subtree as empty. If it appears on the right, then its right subtree will be empty. An example of an expression tree is shown below for the expression ( -a < b ) or ( c + d ) .

Is it helpful? Add Comment View Comments
 

Ques 64. Can we get the remainder of a floating point division ?

Yes. Although the % operator fails to work on float numbers we can still get the remainder of floating point division by using a function fmod( ). The fmod( ) function divides the two float numbers passed to it as parameters and returns the remainder as a floating-point value. Following program shows fmod( ) function at work.

#include <math.h>

main( )
{
printf ( "%f", fmod ( 5.15, 3.0 ) ) ;
}

The above code snippet would give the output as 2.150000.

Is it helpful? Add Comment View Comments
 

Ques 65. How to extract the integer part and a fractional part of a floating point number?

C function modf( ) can be used to get the integer and fractional part of a floating point.

#include "math.h"

main( )
{
double val, i, f ;
val = 5.15 ;
f = modf ( val, &i ) ;
printf ( "nFor the value %f integer part = %f and fractional part = %f",
val, i, f ) ;
}

The output of the above program will be:

For the value 5.150000 integer part = 5.000000 and fractional part =
0.150000

Is it helpful? Add Comment View Comments
 


3) How to build an expression trees ?

4) Can we get the remainder of a floating point division ?

5) How to extract the integer part and a fractional part of a floating point number?

" />

Most helpful rated by users:

©2024 WithoutBook