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

Related differences

Ques 46. How do I print a floating-point number with higher precision say 23.34568734 with only precision up to two decimal places?

This can be achieved through the use of suppression char '*' in the format string of printf( ) as shown in the following program.
main( )
{
int i = 2 ;
float f = 23.34568734 ;
printf ( "%.*f", i, f ) ;
}
The output of the above program would be 23.35.

Is it helpful? Add Comment View Comments
 

Ques 47. Are the expressions *ptr++ and ++*ptr same?

No. *ptr++ increments the pointer and not the value pointed by it, whereas ++*ptr increments the value being pointed to by ptr.

Is it helpful? Add Comment View Comments
 

Ques 48. strpbrk( )

The function strpbrk( ) takes two strings as parameters. It scans the first string, to find, the first occurrence of any character appearing in the second string. The function returns a pointer to the first occurrence of the character it found in the first string. The following program demonstrates the use of string function strpbrk( ).

#include <string.h>
main( )
{
char *str1 = "Hello!" ;
char *str2 = "Better" ;
char *p ;
p = strpbrk ( str1, str2 ) ;

if ( p )
printf ( "The first character found in str1 is %c", *p ) ;
else
printf ( "The character not found" ) ;
}
The output of the above program would be the first character found in str1 is e


div( )...

The function div( ) divides two integers and returns the quotient and remainder. This function takes two integer values as arguments; divides first integer with the second one and returns the answer of division of type div_t. The data type div_t is a structure that contains two long ints, namely quot and rem, which store quotient and remainder of division respectively. The following example shows the use of div( ) function.

#include <stdlib.h>
void main( )
{
div_t res ;

res = div ( 32, 5 ) ;
printf ( "nThe quotient = %d and remainder = %d ", res.quot, res.rem ) ;

Is it helpful? Add Comment View Comments
 

Ques 49. Can we convert an unsigned long integer value to a string?

The function ultoa( ) can be used to convert an unsigned long integer value to a string. This function takes three arguments, first the value that is to be converted, second the base address of the buffer in which the converted number has to be stored (with a string terminating null character '') and the last argument specifies the base to be used in converting the value. Following example demonstrates the use of this function.

#include <stdlib.h>
void main( )
{
unsigned long ul = 3234567231L ;
char str[25] ;

ultoa ( ul, str, 10 ) ;
printf ( "str = %s unsigned long = %lun", str, ul ) ;
}

Is it helpful? Add Comment View Comments
 

Ques 50. ceil( ) and floor( )

The math function ceil( ) takes a double value as an argument. This function finds the smallest possible integer to which the given number can be rounded up. Similarly, floor( ) being a math function, takes a double value as an argument and returns the largest possible integer to which the given double value can be rounded down. The following program demonstrates the use of both the functions.

#include <math.h>
void main( )
{
double no = 1437.23167 ;
double down, up ;

down = floor ( no ) ;
up = ceil ( no ) ;

printf ( "The original number %7.5lfn", no ) ;
printf ( "The number rounded down %7.5lfn", down ) ;
printf ( "The number rounded up %7.5lfn", up ) ;
}

The output of this program would be,
The original number 1437.23167
The number rounded down 1437.00000
The number rounded up 1438.00000

Is it helpful? Add Comment View Comments
 

Most helpful rated by users: