GeekInterview.com
  I am new, Sign me up!
 
GeekInterview.com  >  Interview Questions  >  Programming  >  C
Go To First  |  Previous Question  |  Next Question 
 C  |  Question 404 of 453    Print  
based on type conversion
main()
{
printf("%d",(2.5*2.5));
}

above gives output of 0 plss explain



  
Total Answers and Comments: 2 Last Update: May 22, 2008     Asked by: kartik1218 
  
 Sponsored Links

 
 Best Rated Answer
Submitted by: sachinpatil
 
by default the real number constants (i.e. 2.5 3.14 etc) are considered as double. Double is stored using IEEE floating point standard.
the (2.5 *2.5) gives double. when this double is passed to the printf and printed using %d. function assumes that argument is integer. So there is Data loss of 6 bytes.
and U can think what will be effect of loosing 6 bytes.

Above answer was rated as good by the following members:
kernel32, RoMBiN
February 14, 2008 01:26:53   #1  
sachinpatil Member Since: February 2008   Contribution: 2    

RE: based on type conversion
by default the real number constants (i.e. 2.5 3.14 etc) are considered as double. Double is stored using IEEE floating point standard.
the (2.5 *2.5) gives double. when this double is passed to the printf and printed using d. function assumes that argument is integer. So there is Data loss of 6 bytes.
and U can think what will be effect of loosing 6 bytes.

 
Is this answer useful? Yes | NoAnswer is useful 1   Answer is not useful 0Overall Rating: +1    
May 22, 2008 17:05:05   #2  
kernel32 Member Since: May 2008   Contribution: 6    

RE: based on type conversion
agreed except that we loose 6 bytes rather we can say sizeof(double) - sizeof(int). As in case of linux we loose 4 bytes as sizeof(int) 4 bytes
 
Is this answer useful? Yes | NoAnswer is useful 1   Answer is not useful 0Overall Rating: +1    

 Related Questions

  A switch statement is generally best to use when you have more than two conditional expressions based on a single variable of numeric type.  
Latest Answer : Also, a modern C optimizing compiler will generate the same binary for multiple "if" statements as opposed to a "switch" statement.  However, code that uses "switch" for multiple numeric (symbolically speaking) comparisons ...

A goto statement implements a local jump of program execution, and the longjmp() and setjmp() functions implement a nonlocal, or far, jump of program execution. Generally, a jump in execution of any kind 
Latest Answer : using the normal goto statement we can move only within the function. it is not possible to go from one function to another function.using setjmp and longjmp you can move from one function to another function. but it is very bad programming. since the ...

An lvalue was defined as an expression to which a value can be assigned. Is an array an expression to which we can assign a value? The answer to this question is no, because an array is composed of several 
Latest Answer : Array is not an lvalue..Eg.int arr[5] = {"1","2",.......};here arr[5] has  memory address and now we are assinging values to this.if we write arr[5]; in any function then it will not show any error, mean array does required lvalue ...

Some operating systems (such as UNIX or Windows in enhanced mode) use virtual memory. Virtual memory is a technique for making a machine behave as if it had more memory than it really has, by using disk 
Latest Answer : First of all there is a one sentence definition of Page Thrashing (I believe someone posted a similar answer here):Page Thrashing only comes about when you use Virtual Memory which requires an MMU and "fools" a process into believing that it ...

The register modifier hints to the compiler that the variable will be heavily used and should be kept in the CPU’s registers, if possible, so that it can be accessed faster. There are several restrictions 
Latest Answer : If a variable is defined by using register modifier it tells to the compiler that the variable is used repetedly and that variable executes fastly. Generally register variables are defined in loop counters. This variable stored in CPU registers and access ...

For integral types, on a machine that uses two’s complement arithmetic (which is just about any machine you’re likely to use), a signed type can hold numbers from –2(number of bits – 
Latest Answer : Consider the 3 bitsFor signed int these 3 bits contains both positive and negative valuesyou can find max and min values as follows-2 ^ ( n-1 ) to ( 2 ^ ( n-1 ) - 1 ) ie,  n is no. of bits-4, -3, -2, -1, 0, 1, 2, 3For unsigned int you can find the ...

There are two situations in which to use a type cast. The first use is to change the type of an operand to an arithmetic operation so that the operation will be performed properly.  The second case 
Latest Answer : Type cast should be used in case of if we want to assign a void pointer to a pointer of some data type.eg:void *ptr;int *c;c=(int *)ptr; ...

A type cast should not be used to override a const or volatile declaration. Overriding these type modifiers can cause the program to fail to run correctly. A type cast should not be used to turn a pointer 
Latest Answer : we should not cast the big datatype to smaller one. Like from double to float long to integer. TIn these cases there will be chance of loosing the valuable data itself. ...

Declaring a variable means describing its type to the compiler but not allocating any space for it. Defining a variable means declaring it and also allocating space to hold the variable. You can also 
Latest Answer : int num;This statement is declaration and also defination since it also allocates memory for variable num.But when you use following statementextern int num;It is only declaration since you are not allocating memory here. ...

The benefit of using the const keyword is that the compiler might be able to make optimizations based on the knowledge that the value of the variable will not change. In addition, the compiler will try 
Latest Answer : A side effect benefit:Say you want to pass an argument that you do not want modified, but you do not want to pass by value.Solution pass as constant reference or pointer constant.int someFoo(myDataType const &chunkOfData);orint ...


 Sponsored Links

 
Related Articles

Performing DML Operations on XML Schema Based XMLType Views

Performing DML Operations on XML Schema Based XMLType Views Analyzing the underlying query of the empSch v view discussed in the preceding section you may note that each attribute of the EMP T object used in the select list maps to a certain column of a single table namely emps What this means in pr
 

Concepts of Object-Oriented Programming

Object Oriented JavaScript In this chapter you ll learn about OOP Object Oriented Programming and how it relates to JavaScript As an ASP NET developer you probably have some experience working with objects and you may even be familiar with concepts such as inheritance However unless you re already a
 

What is Data Conversion

Data Conversion, as the name implies, deals with changes required to move or convert data from one physical environment format to that of another, like moving data from one electronic medium or database product onto another format. Every day, data is being shared from one computer to another. This i
 

Conversion in C

How does a conversion occur in C? The data types for numerical operations used in C are integer, float. It is important to know how conversions occur between these two data types in numerical operations. Some of the facts about conversions are given below: Integer having arithmetic operatio
 

SQL Programming

SQL Programming Overview Anybody who has done something for a long time has probably wanted to change how things work at some point or another. A worker at a mill might have found a more efficient way of cutting logs, or a mathematics teacher might have had a hand in changing a school’s al
 

The Interview Snafu

How to turn someone else’s mistake to your advantage Your dream job is about to become reality. A recruiter gave you the heads up about the perfect position at Humungous Conglomerate, Inc. You went through five interviews as well as a battery of psychological tests mandated by their HR de
 

Winning a Job Interview with a Winning Resume

Does your resume unlock your potential, take your skills to the highest level and win you the interview and the job you want now? The job market today is highly competitive and even if you think you have what it takes to get an interview you won’t get over the line without a polished, prof
 

WinRunner Programming Concepts

If you want to create WinRunner scripts that are highly efficient, there are important programming concepts that you will want to become familiar with. Understanding these concepts will provide you with a large number of key benefits. In addition to understanding these concepts, you must also learn
 

Programming Languages Certification

IT Certification programs have several options that will offer you the best knowledge.  By learning everything that you need to know about information technology you will be able to open new doors to your career and personal business desires.  IT Certification offers several vari
 

Neuro-linguistic Programming Methods

Neuro linguistic Programming Methods There are several methods used for performing Neuro linguistic Programming on an individual for obtaining insights into the psyche of the person in order to correct to modify certain patterns of behavior These techniques are also used for Neuro linguistic trainin
 

About Us -  Privacy Policy -  Terms and Conditions -  Contact -  Ask Question -  Propose Category -  Site Updates 

Copyright © 2005 - 2009 GeekInterview.com. All Rights Reserved

Page copy protected against web site content infringement by Copyscape