answersLogoWhite

0


Best Answer

%p is used in a printf statement to show the memory address value of a pointer. It does not show the address of the pointer itself. You can see this with the following program:

#include

int main(void){
int* p;
printf("p: %p x: %x x&: %x\n",p,p,&p);
}

This gave me the following output:

p: 0x33d6d0 x: 33d6d0 x&: bf9a8c10

So %p is a way of formatting the value in a pointer to make it obvious that you are referring to a memory location.

User Avatar

Wiki User

15y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

11y ago

The % symbol is used as the modulo (or modulus) operator. Its function is to return the remainder of a while number division operation. That is, x%y is the same as saying y-(int(x/y)*y), thus if x is 10 and y is 3, x%y is 1, the remainder of 10/3.

This answer is:
User Avatar

User Avatar

Wiki User

10y ago

The % token is the modulo operator, not the percent operator. The modulo operator cannot be overloaded for intrinsic types, you can only overload it for user-defined types.

Since the purpose of modulo is to return the remainder of an integer division, you should only provide a modulo operator overload where your user-defined type is intrinsically integral. One such usage might be to provide modulo functionality for an enum. For instance:

#include<iostream>

enum my_enum

{

zero=0, one, two, three, four, five, six, seven, eight, nine, ten

};

my_enum operator% (my_enum a, my_enum b)

{

int i = a;

int j = b;

return(( my_enum ) ( i % j ));

}

int main()

{

my_enum x = ten;

my_enum y = three;

my_enum mod = x%y;

std::cout<<x<<" % "<<y<<" = "<<mod<<std::endl;

}

Output:

10 % 3 = 1

It should be noted that when the result cannot be guaranteed to be converted to a valid user-defined type, you should not provide a modulo operator. In this it can since all possible results for any two enum values are contained within the enum itself.

The same principal can be applied to classes, provided the class is intrinsically integral. If the class is intrinsically floating point, do not use the % operator, overload the fmod() function instead (#include math.h). The % operator is intuitively an integer division operation and if it is to remain intuitive to your users then it must be implemented as such.

This answer is:
User Avatar

User Avatar

Wiki User

13y ago

"%u" is a printf format specifier that says to convert the next argument into a displayable unsigned decimal.

#include <stdio.h>

int main (int, char*) {

int i;

for (i = 1; i <= 10; ++i) {

printf ("i: %u i squared: %u\n", i, i*i);

}

return 0;

}

This answer is:
User Avatar

User Avatar

Wiki User

15y ago

%u gives the value of the memory location of for eg Integer

%u read an unsigned decimal Integer(scanf)

%u print an unsigned decimal Integer(printf)

This answer is:
User Avatar

User Avatar

Wiki User

13y ago

The percent (%) operator in C and C++ is the modulus operator. It returns the first number mod the second number.

a % b is the same as a - int (a / b) * a

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Use of Percent in C programming?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

What does it mean when use percent 17 or mod any number in Array in C programming?

I mean %17


C programming percentages?

float percent = ((float)CurrentItems / (float)MaxItems);


What is d command for squareroot in C programming?

There are no commands in C-programming, you should use function sqrt from math.h


Can you use C as OOPS?

No, it is a programming language.


Where we use the c language?

In computer-programming.


What is the use of c-language?

Programming, mainly.


Why are use c language?

For is it programming used.


What programming language does the PSP use?

c++


Why you use percent o in C programming?

An integer in octal, for example 25 decimal is 031 octal. (Octal numbers are traditionally preceded by a 0).


What is c and why you use?

C is a programming language, and it's mostly used for Systems Programming. Most kernels these days have at least some C code in them.


Does the C programming language use a virtual machine?

no


How do you use loop in C programming?

#include&lt;stdio.h&gt;