Arithmetic and Logical Expressions


int m, n = 2000, p = 10; // integers m, n, p are declared and n and p are initialized
m = n*p; // Integer m is assigned the product of n and p


float m; int n = 2000, p = 10;	// float m declared, integers n and p declared
				// and initialized
m = n*p;	// The product of n and p, integer value 20000,
		// is promoted to float value 20000.0 and then assigned to m


float m, float n = 2000.25; int p = 10;	// float m declared, float n declared and initialized,
					// int p declared and initialized
m = n*p;	// int p is promoted to float value 10.0, then the product of n and p
		// is assigned to float variable m


int m, int p = 10; float n = 2000.25;
m = n*p;	// int p is promoted to float value 10.0, then multiplied by n
		// the product, float value 20002.5, is then truncated to 
		// integer value 20002 and assigned to integer variable m




Back to Previous Page

Document:
Local Date:
Last Modified On: