its because output screen is not holding, it's displaying output and goes can use scanf("%c",&hold); before return 0 to hold the screen.
and carefull don't forget to declare hold variable as char.
check this:-
int main(){
char as;
/your code.........
return 0;

2^4= 2 2 2 * 2;
2 is multiplied four times.
You can use a loop from 1 to n to multiply 2 to n times.

now % is modulas operator which gives the remainder part i.e,
a % b = R as a=bd + R
for ex.
21 % 2 = 1 as 21=2
10 + 1

Use this concept to get the digits.
and in C 16/10 !=1.6 its 1 decimal part is not considered.

so use both the concepts and you will get the solution

All the best... :)

What I am analyzing(as Narue told not to do that,but due to curiosity i did) is that,

for the parenthesis part a's value is assigned to b, but b outside a is not assigned i.e., it's not containing the value that is done in parenthesis.
so it's (b) containing the garbage value and final calculation is printing garbage number
if suppose the code is:--
int main(void) {
int a=10,b=20;

the code is interpreted as a=10+20-(10)=20
i.e, 'b' inside the parenthesis is assigned the value of a but not the 'b' which is outside the parenthesis, i.e, what is the value of 'b' is assigned is the output as the expression is evaluating as:--

for any value of a and b within the range of int it will give the output..

I hope you have understood the point..:)

x is always storing some value,for the next do while loop
so better you do:-

int persistence( int input ) {

int digit, x , persist = 0;

while ( input > 9 ) {
    do {
        digit = input % 10;
        x = x * digit;
        input = input / 10;
    } while ( input > 0 );

    input = x;

return persist;


NP:- yep I saw it later when I ve done my research on that question and given my time , so I thought to post what i see otherwise i would not ve posted it, and that's why I didn't post the code as it is similar to that of Narue's post.

There's mistake in your logic:--it will also not work for N=2,4 i.e, even numbers. because for N=6 when
i=0 j=5,
i=5 j=1,
what is been seen here is that the array elements are swaped twice for the first half half part, array is reversed and for the next half part it is reversed again making it original array.

The two statements are confusing :--

If the sum is 7 or 11 on the first throw, the player wins.


The player loses by rolling a 7 before making the points.

the code is working as per your logic


int main ()
int i,d1,d2,sumd;
int winf = 0, lostf = 0, winp = 0, lostp = 0;
// printf("This program will simulate the game of craps for 100 times.\n");

for (i=0; i<10; i++) {
d1 = rand()%6+1;
d2 = rand()%6+1;
sumd = d1 + d2;
printf("%d %d sum:-%d\n",d1,d2,sumd);
if (sumd==7 || sumd==11) {
printf("You rolled a 7 or an 11, you win.\n");
if (sumd==2 || sumd==3 || sumd==12) {
printf("You rolled a 12, a 3, or a 2, you lose.\n");
if (sumd==4 || sumd==5 || sumd==6 || sumd==8 || sumd==9 || sumd==10) {
d1 = rand()%6+1;
d2 = rand()%6+1;
sumd = d1 + d2;
if (sumd==7) {
printf("You rolled a 7, you lose.\n");
if (sumd==4 || sumd==5 || sumd==6 || sumd==8 || sumd==9 || sumd==10) {
printf("You rolled your points, you win.\n");

printf("First roll wins: %d, First roll loses: %d, Second roll wins: %d, Second roll loses: %d. ", winf, lostf, winp, lostp);



cdudefire commented: Helpful +1

[QUOTE]if (sumd=7,11)[/QUOTE]

line 18,22,26,34, for or operation the condition will be like this:-
[CODE]if(sumd==7 || sumd==11)[/CODE]

We can make a generalized functions with the help of void pointer like this:-


void abc(void a, int b) {
format[] = {"%d ", "%c "};
printf(format[b-1], a);
int main()
return 0;

check [URL=""]this link[/URL] for more information..:)

there are basically 5 data types in C.
Int, Char, Float , Double and Void.

The type Void either explicitly declares a function as returning no values or creates generic pointers.

when we declare
int i;
int *p;

when we declare p as an integer pointer means it will store the address of integer type data.
As I told Void pointer is a generic pointer which means it can store the address of other types as required.
for eg.


int main()
int i=5;
char c='A';
void p;
printf("%d ",
printf("%c ",
return 0;


here as you see first address of int is stored in void p.
to access the value at that address you have to typecast with the type which is stored in that void ptr.
here to access value at p we have to use

its kind of big endian and little endian thing , means-

These are d terms dat describe the order in which a sequence of bytes are stored in computer memory.

Little Endian means that the lower order byte of the number is stored in memory at the lowest address, and the higher order byte is stored at the highest address. That is, the little end comes first.

For example, a 4 byte, 32-bit integer

Byte3 Byte2 Byte1 Byte0

will be arranged in memory as follows:

Base_Address+0 Byte0
Base_Address+1 Byte1
Base_Address+2 Byte2
Base_Address+3 Byte3

Example :Intel processors use "Little Endian" byte order.

"Big Endian" means that the higher order byte of the number is stored in memory at the lowest address, and the lower order byte at the highest address. The big end comes first.

Base_Address+0 Byte3
Base_Address+1 Byte2
Base_Address+2 Byte1
Base_Address+3 Byte0

Motorola, Solaris processors use "Big Endian" byte order.

google it for more information..

Now whats happening here iPtr is a pointer storing integer address.
iPtr will represent the same address as represented by casting it with char i.e, (char)iPtr.
but here we are limiting the value at that address to 1 byte instead of sizeof(int) byte by casting it, and we are returning the value as an int not as a char.
so 1 byte= 8 bits. and that binary conversion , the little endium things (as intel processor) are taken into consideration for value at address of (char
)iPtr and next bit for (char*)iptr+1.

:icon_idea: [U][B][COLOR="red"]MUST GO ...

i++ is same as i=i+1, and its required as per conditions of program.
inbuilt thing unable to get your words. Machine only understand the thing which we perform and follow our instructions. if i=0 then how it will increment automatically as machine is not having any sense until we tell him to do.
for decrement you can use like,
printf("hi ");
when n=0, while(0) condition wull false and automatically loop will end.

Still your words and not understood , refer with exact code.

Yup as told by gerard4143 and asit mahato.
Saurav:-Don't get confused by seeing negative sign as output.

for eg:--
int i = 449; int iPtr = &i;
printf("%d %d",
((char)iPtr), ((char*)iPtr+1) );}

output is -> -63 1.

As binary of 449 is 00000001 11000001

for 11000001, most significant bit(MSB) is 1 which is sign bit if there is 0 means number is positive and if there is 1 i.e, number is negative here it is 1 means number is negative. so converts this binary into its 2's complement which is 00111111(63 in decimal but -(minus) sign will be there because of 1 in MSB so -63).
for 00000001 MSB is 0 so number is positive and nothing to worry.
now final binary form is:--
00000001 00111111
= 1 -63 (in decimal)
so output will be -63 and 1.

okay.. keep enjoy programming.. :)

Yup instead of talking like an unprofessional, i should have used sizeof(int) instead.

@gerard4143:-[QUOTE] p = (char)(p + sizeof(int) ELEM_POS);[/QUOTE]
why are you multiplying sizeof(int) with 2.
it will print element of x[2] instead of x[1].

what is the use of command line argument here...I didn't understand. Please Explain.:-O

[CODE] p=(char)((int)(p+4));



Both increments are working correctly in my compiler giving output 3.
which compiler are you using..??

char* generally stores the address of char type,here it stores the address of int type.
since char occupy 1 byte memory space while int occupy 2 byte or 4 byte(machine & compiler dependent) space in memory. so on increment in p it will refer to next byte incremented by 1 while the next value is 2 or 4 byte from that address of arr . what I mean to say is that.

Suppose arr has an address of 2000 so p=arr means p has an address of arr.
but arr is of type int so arr[1] will be stored in address 2004.
and on increasing the pointer with value 1 it will point to 2001(as it is of char type) which doesn't contain the value arr[1]. so it will result out 0.

you can refer to arr[1] by :-
p=(int)(p+2);//if int take 2 bytes
)(p+4);//if int take 4 bytes

geeksforgeek commented: helpfull reply +0

Segmentation fault is due to an attempt of access of an area of memory that is not allowed to be accessed.
Common causes are:-
Improper format control string in printf or scanf statements.
Forgetting to use & on the arguments to scanf.
Accessing beyond the boundaries of an array.
Failure to initialize a pointer before accessing it.
Incorrect use of the "&" (address of) and "*" (dereferencing) operators.

Macros and External Variables are really two different things:-
[B]Macros[/B] are preprocessor directive means they are executed before the actual compilation of code begins.They are started with #define.

[B]External Variables[/B] are used for declaration of variables(local), they can be defined any where in the programs.By default value stored in global is 0 and declared as int type.