none
CONTINUOUS GAME RRS feed

  • Question

  •  

    Hi friends lets play a game I will put one question.And you have to solve it.And the one who solves this post another question too.Ans Continue the link in this way.

     

     

    Write a valid one line c expression in place of the -----  in the following code snippet so that it check that if the no 'n' is 

    a power of two or not.

     

     

    if(-------)

    {

    printf("Its a power of 2");

    }   

    else

    {

    printf("Its not");

     

    }

    Friday, September 28, 2007 11:44 AM

All replies

  • it shud be "pow(2,log(n)/log(2))==n"...

    My ques:
    What will be the output of below prog.?

    #define int char

    main()
    {
        int i=65;
        printf("sizeof(i)=%d",sizeof(i));
    }
    Friday, September 28, 2007 1:42 PM
  •  

    O/P Will be :

    sizeof(i)=1

    Friday, September 28, 2007 3:35 PM
  • sizeof(i)=1 is the output..

     

    well my question is one which i got an error during some coding..

     

    consider a part of code

     

    .

    .

      int tm=originalNumber.size()-10;
      int i=originalNumber.size()-1;
      for(;((i>tm)&&(i>=0));i--)

    .

    .

    .

     

     

    and

     

    .

    .

    .

     for(int i=originalNumber.size()-1;((i>originalNumber.size()-10)&&(i>=0));i--)

    .

    .

    .

     

    where originalNumber is string vector.

    but the problem is that the 1st code is exiting normaly but the second code exit without entering into the for loop even if

    the required condition is met.

    Any guess why it`s happening so???

     

    ofcourse i don`t know the answer !!!

    Friday, September 28, 2007 3:52 PM
  • the ans will be sizeof(i)=1 since we define int as a char type so the no bytes occupied by char is 1 so the sizeof(i) will be surely 1...

    My Ques:
    #include<stdio.h>
    main()
    {
    char s[]={'a','b','c','\n','c','\0'};
    char *p,*str,*str1;
    p=&s[3];
    str=p;
    str1=s;
    printf("%d",++*p + ++*str1-32);
    }

    Friday, September 28, 2007 3:58 PM
  •  

    Answer ::

     

     77

     

    [  11+ 98 - 32 ]

     

    My Question !!

     

    Code Block

     main()

    {

    char *p="hai friends",*p1;

    p1=p;

    while(*p!='\0') ++*p++;

    printf("%s   %s",p,p1);

    }

     

     

     

    Friday, September 28, 2007 5:07 PM
  • the Answer to the above question is
    It incremnets the ascii value of each  character in the string and then prints the string but the pointer p points towards null
    so only pl prints the modified string.

    The next quetion is to print the no of set bits in the binary representation of a given decimal no.
    Saturday, September 29, 2007 8:35 AM
  • let me answer for my question stated above...

    Answer:
    M
    Explanation:
    p is pointing to character '\n'.str1 is pointing to character 'a' ++*p
    meAnswer:"p is pointing to '\n' and that is incremented by one." the ASCII
    value of '\n' is 10. then it is incremented to 11. the value of ++*p is 11.
    ++*str1 meAnswer:"str1 is pointing to 'a' that is incremented by 1 and it
    becomes 'b'. ASCII value of 'b' is 98. both 11 and 98 is added and result is
    subtracted from 32.
    i.e. (11+98-32)=77("M");
    Tuesday, October 2, 2007 4:25 PM