Narue 5,707 Bad Cop Team Colleague

How do you know it can't open the file? Does your error message print? If so, change it to this for more details:

perror ( "Error: file could not be opened" );
Narue 5,707 Bad Cop Team Colleague

Look up the escape characters for C. You have the option of an octal escape character and a hexadecimal escape character.

Narue 5,707 Bad Cop Team Colleague

>bool isOdd = result & 1;
I wouldn't necessarily recommend it unless you can prove that the remainder operator is noticeably slow and bitwise AND is significantly faster. Decreasing readability for dubious performance gains smacks of bad practice.

Narue 5,707 Bad Cop Team Colleague

>I was told to put these in so that I can see the ending
>result without the program terminating itself

Whether that happens depends on how you run the program. It's also not as simple as you were told. If the stream is clean, all you need to do is call cin.get(). But if the stream is dirty, it gets complicated. Note that cin.clear() doesn't "flush" the input stream, it clears error flags.

>Or is that the reason you left return 0; out? Is it needed?
I left out the return statement because in standard C++, 0 is returned from main automatically. return 0; at the end is redundant.

Narue 5,707 Bad Cop Team Colleague

>using namespace std;
You can remove this line by explicitly qualifying the std namespace on your names.

>cin.clear ();
>cin.get ();
>cout << endl;

These lines are unnecessary. Further, you can merge the input into a single prompt:

std::cout<<"Enter two numbers: ";
std::cin>> a >> b;

>cout << result; //Displays the result
>cout << endl;

These lines can be merged (and endl is often unnecessary):

std::cout<< result <<'\n';

>if (result % 2 == 0) cout << "your result is even";
>else cout << "your result is odd";

You can make use of the ternary operator here:

std::cout<<"Your result is "<< (result % 2 ? "odd" : "even") <<'\n';

>std::cout<< result <<'\n';
>std::cout<<"Your result is "<< (result % 2 ? "odd" : "even") <<'\n';

These two lines can be merged, but the line length starts getting awkward:

std::cout<< result <<"\nYour result is "<< (result % 2 ? "odd" : "even") <<'\n';

>cin.clear ();
>cin.get ();
>return 0;

These are all unnecessary.

All suggestions included:

#include <iostream>

int main()
{
  int a, b, result;

  std::cout<<"Enter two numbers: ";
  std::cin>> a >> b;

  result = a + b;

  std::cout<< result <<"\nYour result is "<< (result % 2 ? "odd" : "even") <<'\n';
}
Narue 5,707 Bad Cop Team Colleague

Closes? I'd more expect it to hang since the first loop of the combination calculator is infinite. Though it's quite likely the undefined behavior of overflowing your data types causes a crash. Can you describe what happens when the program "closes"?

Narue 5,707 Bad Cop Team Colleague

>128 only the eight is displayed as text. Any ideas?
I already told you that your algorithm is broken. It'[s pretty easy to brute force the algorithm if you're limited to a range of [-999, 999], you just have to be careful about the order in which you process digits.

Here's an example to give you an idea of how it might be done:

#include <iostream>
#include <sstream>
#include <string>
#include <cstdlib>

namespace {
  const std::string ones[] = {
    "",     "one", "two",   "three", "four",
    "five", "six", "seven", "eight", "nine"
  };

  const std::string teens[] = {
    "ten",     "eleven",  "twelve",    "thirteen", "fourteen",
    "fifteen", "sixteen", "seventeen", "eighteen", "nineteen"
  };

  const std::string tens[] = {
    "",      "",      "twenty",  "thirty", "forty",
    "fifty", "sixty", "seventy", "eighty", "ninety"
  };

  std::string int_to_word ( int value )
  {
    std::ostringstream out;
    bool neg = value < 0;

    value = std::abs ( value );

    int digits[3] = {0};

    for ( int i = 2; i >= 0 && value != 0; i-- ) {
      digits[i] = value % 10;
      value /= 10;
    }

    if ( neg )
      out<<"negative ";

    if ( digits[0] == 0 && digits[1] == 0 && digits[2] == 0 )
      out<<"zero";
    else {
      if ( digits[0] != 0 )
        out<< ones[digits[0]] <<" hundred ";

      if ( digits[1] != 0 ) {
        if ( digits[1] == 1 )
          out<< teens[digits[2]];
        else {
          out<< tens[digits[1]];

          if ( digits[2] != 0 )
            out<<' '<< ones[digits[2]];
        }
      }
      else
        out<< ones[digits[2]];
    }

    return out.str();
  }
}

int main()
{ …
Narue 5,707 Bad Cop Team Colleague

strcat expects a valid C-style string (ie. an array of char terminated by '\0'). In your case, you failed to meet the requirement that the array is terminated by '\0', so you've invoked undefined behavior. This should help:

char *cdisp;
cdisp = new char[200];

// Add the following line
cdisp[0] = '\0';

if( inum < 0)

Your algorithm is mixed up too. Expect the words to be jumbled.

Narue 5,707 Bad Cop Team Colleague

>I feel disturbed when two geeks arguing each other
It's all in good fun, no worries.

>I dont need couple of years i just need couple of months
Then more power to you.

Narue 5,707 Bad Cop Team Colleague

>i didn't attack you
Please don't insult everyone's intelligence. Your first reply to my post was clearly a personal attack.

>i just defend my fellow Asian being criticized by unworthy critics like you
Ignoring this "fellow Asian" crap, what makes you think I'm an unworthy critic? As I've said once before in this thread, I have quite a bit of experience conducting interviews, which makes me qualified to comment on the OP's answers. You have yet to show that any of my comments are false, which suggests that you're full of it and simply attacking me out of personal dislike.

>its ok if you criticize someone in a good way in a constructive way not by insulting them.
The very nature of criticism means that even the slightest sensitivity will result in someone being insulted. I tell it like it is, without any sugar coating. Just because you're insulted doesn't mean I'm not right. Get over it.

>i can say im a lot smarter than you coz. i can understand
>your language but you cant understand mine...

If you're so much smarter than me, why is it that I can see how utterly ridiculous that statement is while you apparently don't?

>im not that fluent in english coz im not born american and
>i can't elaborate well on my arguments.

You can't elaborate on something that doesn't exist. While you might disagree (probably because you think ad hominem attacks …

Narue 5,707 Bad Cop Team Colleague

>Is it true that the finally block doesn´t execute either ?
The finally block always executes, whether an exception was thrown or not.

Narue 5,707 Bad Cop Team Colleague

>And oh, by the way, you can't defeat a genius through hard work.
Sure you can, but only if the genius doesn't also work hard to maintain a gap in ability, and the subject/skill doesn't have a hard limit. In the former case, if a genius is lazy then you can work hard to catch up and exceed him. In the latter case, given enough time both parties will reach the same level because at a certain point the genius can't progress further. But that doesn't make as good of a signature.

>but to me shes just nobody! ahahaha
If I were nobody to you, you wouldn't have bothered to attack me out of the blue like that. It's more likely that you feel threatened for some reason and lashed out to secure a (false) sense of authority. To me you're a source of entertainment. It would be more fun if you didn't fail miserably at debate, but owning people in an argument is also amusing, so keep it coming. :)

>accurately comment?
Yes, quite accurate. If you disagree then make some counter-arguments. I can defend my comments, but can you disprove them without falling back on ad hominem?

>what a feeler
When one resorts to name calling, it generally means that one has run out of intelligent things to say.

Narue 5,707 Bad Cop Team Colleague

He asked for comments and I commented. I'm not going to blow sunshine up his ass just to make him feel good. Honesty and objectivity are far more useful than lies and fear of offending people.

>you criticize people like your a super genius...
I criticize where appropriate.

>your too full of yourself...
I don't worry about false modesty just to make people feel better about themselves.

>you think your so smart?
I think I'm experienced enough, having conducted many interviews, to accurately comment on the OP's answers.

Narue 5,707 Bad Cop Team Colleague

Q: what are the different stages in SDLC?
Me: Requirement Analysis -> Design -> coding -> Testing -> Implementation and Maintenance

Canned answer to a vague question, not promising at all. I'd expect you to dig for more details before coming up with an answer. For example, which methodology am I talking about? Interviewers will often ask questions that are meant to prompt a series of questions from a good candidate.

Q: what are the advantages of C++ over C?
Me: C++ is an Object Oriented Programming Language while C is a Procedure oriented language
Q: Other than that?
Me: Sorry madam, I don’t know.

Superficial answer, no depth of understanding exhibited. The "advantage" implied by the answer is not really an advantage. All in all a very poor answer. Your inability to come up with anything else suggests that you have only a rudimentary knowledge of those languages.

Q: what are the advantages of Using C?
Me: Don’t know madam

While "I don't know" is a promising answer in and of itself, complete failure to know even the most basic answer to this question is not a good sign. Assuming basic knowledge of C is important for getting the job, I'd have crossed you off my list by now.

Q: what are the advantages of .NET framework?
Me: Robustness, security, RAD, Interoperability….

Canned answer, lots of empty calories, and no real display of understanding. Not a …

Salem commented: Seems about right to me :) +0
Rashakil Fol commented: A++ would read again, and did +0
Narue 5,707 Bad Cop Team Colleague

>I see the "new" operator is very different from java one, is it right?
Not especially. The Java new expression creates an object of the specified type, calls the specified constructor, and returns a reference to the object. This is pretty much identical to C++ where a new expression creates an object of the specified type, calls the specified constructor, and returns a pointer to the object. The only real difference (at the superficial level you should be comparing C++ and Java) is you can do more with a C++ pointer than a Java reference.

chaienbungbu commented: Thank for your info. +1
Narue 5,707 Bad Cop Team Colleague

>Don't use system("PAUSE"). It is causing unncessary
>overhead to your program by making system calls.
system("PAUSE") is typically used to keep a command prompt window open after the program is finished. Overhead is irrelevant when the very nature of the system call is I/O bound. More important is the fact that a malicious party can easily replace the pause program with malware, and the program will innocently run it with it's own privileges. It also hurts portability because the pause program isn't standard across platforms.

Narue 5,707 Bad Cop Team Colleague

>ne?
Un, wakata.

Narue 5,707 Bad Cop Team Colleague

w and w->word are two separate pointers that (as you say) were allocated using two separate calls to the memory manager. Therefore, the code you posted is correct. Make sure you don't call free(w->word) in a loop, or in two different places.

Narue 5,707 Bad Cop Team Colleague

>In standard C++ you can't. If your compiler is one of those that has enhancements,
>there may be a way, but it's non-standard and therefore not recommended.

I can only assume you were running on autopilot and didn't proofread your post, because that's just stupid.

If there's a standard alternative, non-standard solutions aren't recommended. But if there's not a standard alternative, you don't have a choice if you want to implement the feature. Are you suggesting that the OP not do what he wants at all because it can't be done with standard C++?

Narue 5,707 Bad Cop Team Colleague

>I still don't understand why I need to use namespace
Because the standard library places everything in the std namespace. If you want to use the standard library, you have no choice but to at least mention that namespace somewhere in your code.

>What happens if I don't use it?
You don't have to create your own, but you do have to use the namespaces created by others.

>And how do I define a namespace?
Wrap your code in a namespace block:

// Add foo in the jsw namespace
// If jsw hasn't been defined yet, create it
namespace jsw {
  void foo()
  {
    //...
  }
}

>Can I use <math> and <ctype>...or do i *have to* use c in front of them?
You can use <cxxxx> or <xxxx.h>, but <xxxx.h> is not recommended (it's also officially deprecated) because the names won't be in the std namespace, and unless you've memorized every name in the C library, you're more likely to get conflicts. However, this only applies to the standard headers inherited from C.

>How do I use system("cls")?
You just did. :) Don't forget to include <cstdlib> though:

#include <cstdlib>
#include <iostream>

int main()
{
  std::cout<<"Test\n";
  std::system ( "CLS" );
  std::cout<<"Another test\n";
}
Narue 5,707 Bad Cop Team Colleague

>Can anyone tell me why?
Your pointer is uninitialized. It's not a pointer to infinite memory, it's an invalid pointer. Expect crashes and unpredictable results, because that's what happens with undefined behavior.

>I wanted to take a line input of infinite length.
It's not that easy. You need to read into a single character or a block of characters, resize your buffer, and then copy into it until input is complete. For example:

#include <stdio.h>
#include <stdlib.h>
#include <errno.h>

#define AGETS_PARTIAL 0x8F5

/*
  Read characters into a result string until '\n', EOF, or error
    * NULL is returned if no characters were stored,
      otherwise the current string is returned
    * The '\n' character is not retained
  The result string is dynamically allocated and must be freed
  errno is set to AGETS_PARTIAL if a partial string is returned
*/
char *agets ( FILE *in )
{
  char *buf = NULL;    /* Destination buffer */
  size_t capacity = 0; /* Current buffer capacity */
  size_t size = 0;     /* Current number of characters in the buffer */

  for ( ; ; ) {
    int ch;

    if ( size == capacity ) {
#define CHUNK_SIZE 8
      /* Make space for the null character, but don't include it in capacity */
      char *save = realloc ( buf, ( capacity += CHUNK_SIZE ) + 1 );
#undef CHUNK_SIZE

      if ( save == NULL ) {
        if ( buf != NULL )
          errno = AGETS_PARTIAL;

        break;
      }

      buf = save;
    }

    /* …
tux4life commented: Nice code :) +6
Narue 5,707 Bad Cop Team Colleague

>but i want to know if there is something better.
Better how? You've got the basic idea, so any "bettering" would be adding fluffy features on top of the basics.

Narue 5,707 Bad Cop Team Colleague

>2) when the person enters his password it should not be visible.
You need a way of reading raw input without echo. The most well known function that does this is getch, from <conio.h>, but I can't recommend that because I don't know what compiler you're using. You can search this forum for questions about inputting a password for details. I'm sure I've posted complete code at least a few times.

Narue 5,707 Bad Cop Team Colleague

This is where you write a test program to find out for yourself:

#include <stdio.h>

int main ( void )
{
  const char *s = "test";
  const char *t = "temp";

  do
    printf ( "s: %c\tt: %c\n", *s, *t );
  while ( *s++ == *t++ );

  return 0;
}

*s and *t are compared, then s and t are incremented. If you break the expression down, it looks something like this:

*s == *t;
++s;
++t;
Narue 5,707 Bad Cop Team Colleague

When you changed int to T in the iterator parameters, they became dependent types. You need to specify that iterator refers to a type name:

template <class T>
int number(
  T n, 
  typename vector<T>::iterator start, 
  typename vector<T>::iterator end)
{
  int count = 0;
  for(start; start != end; start++)
  {
    if(n == (*start))
      count++;
  }
  return count;
}

Or you could just use the std::count template function from <algorithm>. It does the same thing as your function.

Narue 5,707 Bad Cop Team Colleague

>To specify a 64-bit integral (long long) type, use the LL or ll suffix.
However, note that long long is not standard C++ yet (C++0x is nearing completion though), so you might encounter either complete failure or a difference in the details with various compilers.

kvprajapati commented: Agree! +6
Narue 5,707 Bad Cop Team Colleague

Be careful with your recursive functions. In your case, delete1 tries to access a dangling pointer because your if chains aren't all connected. Try this instead:

void delete1(node *&tree,  int data)
{
    if(tree->data==data)
        delete2(tree);
    else if(tree->data<data)
        delete1(tree->right,data);
    else if(tree->data>data)
        delete1(tree->left,data);
}
Narue 5,707 Bad Cop Team Colleague

>Maybe this will give a clearer meaning of what I'm trying to do.
strtok doesn't make a copy of the token, it modifies the original string by adding a null character at the end of each token and then returns a pointer to it. Every pointer in token, and consequently every pointer in CopyAllc.info, is actually a pointer to your dynamically allocated memory. When the memory goes away, so do all references to it.

You need to make the copy yourself:

// Was CopyAllc.info[i] = token[i];
{
  CoypAllc.info[i] = malloc ( strlen ( token[i] ) + 1 );

  if ( CopyAllc[i] == NULL ) {
    /* Handle the error */
  }

  strcpy ( CopyAllc[i], token[i] );
}

Now for some general commments.

>FBUFFER = malloc(sizeof(char)*lSize);
sizeof(char) is guaranteed to evaluate to 1, so you can simplify your call to malloc:

FBUFFER = malloc ( lSize );

Also, an unadorned size is suspicious when allocating memory for a string. Usually I'd expect +1 for the null character:

FBUFFER = malloc ( lSize + 1 );

>for(i = 0; i < sizeof(token); i++){
There are two things I'd recommend on this:

  1. sizeof(token) is not sufficient to get the size of an array unless it's an array of char. You need sizeof token / sizeof *token because token is an array of pointers to char. sizeof gives you the total bytes in the array, and dividing it by the size of …
asm2hex commented: Helped me greatly. +1
Narue 5,707 Bad Cop Team Colleague

>What I don't understand is when did Apple and Orange instances get created?
They didn't. You're invoking undefined behavior because _mInstance is a null pointer. However, neither squeeze nor cut access non-static data members, so there's a good chance that both functions will run properly.

Here's an example of the phenomenon:

#include <iostream>

class Example {
public:
  void print() { std::cout<<"It works?!\n"; }
};

int main()
{
  // Undefined! Don't rely on this
  ((Example*)0)->print();
}

It might blow up on you, that's how undefined behavior works, but the idea is that member functions are actually just regular functions with a hidden this parameter. The above example might be translated by the compiler into something like so:

#include <iostream>

class Example {};

void print__Example_00 ( Example * const this )
{
  std::cout<<"It works?!\n";
}

int main()
{
  // Undefined! Don't rely on this
  print__Example_00 ( (Example*)0 );
}

Notice that the this parameter isn't ever dereferenced, that's the key. If you try to access an instance member of the class, then the pointer would be dereferenced and you'd suffer whatever ills occur when trying to access a null pointer.

>An even more crazy version? What happened?
Templates that aren't called don't get instantiated. You can have all kinds of crap that causes a compiler to puke and it'll go through cleanly if you never instantiate the template.

Narue 5,707 Bad Cop Team Colleague

>There seems to be a lot of conflicting opinions on whether one
>should learn C before C++ or its OK to go straight in to C++?

Anyone who claims that one is a prerequisite for the other is misinformed. You can learn them in either order, just pick the language that appeals to you more. But I do recommend learning both eventually.

Narue 5,707 Bad Cop Team Colleague

>Shouldn't this be an error?
It is an error. Just because it doesn't blow up spectacularly when you test doesn't make it any less wrong.

Narue 5,707 Bad Cop Team Colleague

>note that my native language is not english.
What a convenient excuse, but Your English is good enough, so I'm not buying it.

>a person is insulting, only if he/she intends to insult.
Communication is a two way street, genius. Even if you don't intend to insult, the people you're talking to can still be insulted by your words. Once again, your attitude is extremely self-centered. If you don't intend to give insult, you should probably choose your words more carefully.

>I had only one question in this thread
Last I checked, you've started more than one thread.

>I control my expectations freely
Yes, that's the problem.

Narue 5,707 Bad Cop Team Colleague

>I didn't insult.. I said what I thought.
Just because you're being honest doesn't mean you're not being insulting. You have to be pretty self-centered to suggest that we're not helpful due to your inability to ask a smart question and have reasonable expectations.

Whether I know the answer to your questions or not, don't expect me to help you. You'll find more and more people of that particular opinion as you burn your bridges with reckless abandon.

Narue 5,707 Bad Cop Team Colleague

>But assumingly i sized it to 9 rather than 8, when i call the
>binaryinput to print the input isn't the null going to appear again at
>the back of the output?

No, you have to do it yourself. Local variables are not initialized to any value.

>or i could asummingly add = {0} at the back. But what does that do?
It initializes all elements of the array to 0.

Narue 5,707 Bad Cop Team Colleague

...

Well, you could look at the definition of binaryinput in any of the complete examples I gave you. Or you could do binaryinput[8] = '\0' anywhere between defining binaryinput and printing it (assuming you properly sized the array to 9 rather than 8).

Narue 5,707 Bad Cop Team Colleague

>By the way how come my output binay how there is some
>funny attachment at he back of my output code like - '''

Probably because you didn't terminate the binaryinput array with the '\0' character. I do believe this was the very first thing I mentioned in this thread.

Narue 5,707 Bad Cop Team Colleague

Sorry dude, I have a hard time believing that any legitimate school project would require you to make a robust keylogger.

Narue 5,707 Bad Cop Team Colleague

>Hint, initialize your variables.
It's not that simple. An untrained eye could easily say that the variables are initialized prior to use.

>for(int i=0, sum=0; i<=4; i++)
You're actually defining a new sum variable here, not initializing the parameter named sum. The new variable hides the old one, and any changes you make in the loop modify the local variable rather than the reference parameter. You need something more like this:

void getNum(int& num,int& sum)
{
  cout<<"Please enter 5 numbers:"<<endl;
  sum = 0;
  for(int i=0; i<=4; i++)
  {
    cin>>num;
    sum=sum+num;
  }
  return;
}
Narue 5,707 Bad Cop Team Colleague

You're using getche for input, so you could interactively force either '0' or '1' and save yourself validation efforts after the fact:

#include <stdio.h>
#include <math.h>
#include <conio.h>

int main ( void )
{
  char binaryinput[9] = {0};
  int result = 0;
  int i;

  printf ( "Please enter an 8-bit binary number: " );
  fflush ( stdout );

  for ( i = 0; i < 8; )
  {
    /* Don't echo until we know it's a valid character */
    int ch = getch();

    if ( ch == '0' || ch == '1' )
    {
      binaryinput[i++] = (char)ch;

      /* Echo the character manually */
      putch ( ch );
    }
  }

  for ( i = 0; i < 8; i++ )
  {
    if ( binaryinput[i] != '0' )
      result += (int)pow ( 2, 7 - i );
  }

  printf ( "\n%s binary is %d decimal\n", binaryinput, result );

  return 0;
}

Another option is to allow the user to enter the string completely, then validate it. This would be your best option if you used standard input rather than the non-standard conio library:

#include <stdio.h>
#include <math.h>
#include <conio.h>

int main ( void )
{
  char binaryinput[9] = {0};
  int result = 0;
  int i;

  printf ( "Please enter an 8-bit binary number: " );
  fflush ( stdout );

  for ( ; ; )
  {
    /* Get a valid binary string */
    for ( i = 0; i < 8; i++ )
      binaryinput[i] = getche();

    /* Validate input */
    for …
Narue 5,707 Bad Cop Team Colleague

>This should be most performant unless Narue says otherwise
AFAIK, country codes are organized in a prefix hierarchy, so a trie would be the most direct data structure for the hierarchy. Obviously reusing an existing library is ideal, but because there aren't many country codes, you could use just about anything and it'll be fast enough.

However, unless there's a required format for the input string where the country code is separate, some kind of prefix data structure (like a trie) where the query can be refined at each subsequent prefix would make the job much easier.

Narue 5,707 Bad Cop Team Colleague

The base case is when you want the recursion to stop going deeper and return back up the chain. In your case it's probably when n is less than zero.

Narue 5,707 Bad Cop Team Colleague

Are you using an installer or just copying the files manually to each new machine?

Narue 5,707 Bad Cop Team Colleague

Here's an example that shows your most immediate problem:

#include <cstring>
#include <iostream>

void foo ( char *p )
{
  p = new char[4];
  std::strcpy ( p, "foo" );
}

void bar ( char **p )
{
  *p = new char[4];
  std::strcpy ( *p, "bar" );
}

void baz ( char*& p )
{
  p = new char[4];
  std::strcpy ( p, "baz" );
}

int main()
{
  char *p = 0;

  foo ( p );
  std::cout<<"p == "<< ( p != 0 ? p : "(null)" ) <<'\n';
  delete p;

  bar ( &p );
  std::cout<<"p == "<< ( p != 0 ? p : "(null)" ) <<'\n';
  delete p;

  baz ( p );
  std::cout<<"p == "<< ( p != 0 ? p : "(null)" ) <<'\n';
  delete p;
}

foo is equivalent to what you're doing now. bar and baz are two ways to fix the problem. The problem is that pointers are passed by value, so when foo assigns to p, it's actually modifying the copy rather than the original. Passing a pointer to the pointer or a reference to the pointer allows the function to access the original pointer.

Fix that and we can talk about any further problems.

Narue 5,707 Bad Cop Team Colleague

It looks like you're mixing solutions, and you added too much fluffy code without getting a solid solution first.

>char binaryinput[8];
If you're going to print binaryinput as a string later, you need to leave room for a null character at the end.

>printf("\tPlease enter an 8-bit binary bits:");
If you don't print a newline, be sure to call fflush so that the output is guaranteed to be shown before blocking for input. You're not likely to have a problem on Windows systems, but this is a portability concern.

>for(i=7; i<8; i--)
You really only need to loop from 0 to 8. No tricks needed, and this loop is severely broken.

>if(binaryinput[0] == '1')
Obviously you'll need to compare against binaryinput[i] rather than binaryinput[0] , otherwise the loop won't work as intended.

result = binaryinput[i] * pow(2,0);

is pointless as written, but I suspect what you wanted was to add the result of pow to result :

result += (int)pow ( 2, 7 - i );

The cast to int will silence a warning about double truncation, and 7-i gets you the right exponent from the loop index.

>else if(binaryinput[0] == '0')
This comparison isn't necessary as work only needs to be done for set bits.

All of the problems are pretty simple, and it looks like you have a fairly good idea of how the solution should work, so I'll give you my version of the …

Narue 5,707 Bad Cop Team Colleague

Static data members aren't defined within the class definition, they're only declared. You need to provide a definition as well:

class foo {
  static int x; // Declaration
};

int foo::x; // Definition

The definition should be in your implementation file rather than your header file if you've done such a split with your class.

Narue 5,707 Bad Cop Team Colleague

>If so, how we can free that memory?
Assuming the pointer was dynamically allocated in the function (which it wasn't in the case of foo), you either free it within the function or suffer a memory leak.

>since size of a pointer(**ptrtoptr is a pointer) is always fixed?
>suppose instead of value(int) we are using a value(char) is it correct??

That's the whole point of the construct. If you take the size of the pointer object you're assigning to, the type is deduced automatically. Thus, if/when the type of the pointer changes, you don't need to change the call to malloc:

char *a = malloc ( sizeof *a ); // Allocates a char
int *b = malloc ( sizeof *b ); // Allocates an int
double *c = malloc ( sizeof *c ); // Allocates a double

struct coord { int x; int y; };

struct coord *e = malloc ( sizeof *d ); // Allocates a coord

Notice that the call to malloc follows the same pattern, and that the type is only specified in the declaration (not the call to malloc). Compare that with the more traditional way you were using:

char *a = malloc ( sizeof ( char ) ); // Allocates a char
int *b = malloc ( sizeof ( int ) ); // Allocates an int
double *c = malloc ( sizeof ( double ) ); // Allocates a double

struct coord { int x; int y; };

struct …
sree_ec commented: thanks for the detailed reply +1
Dave Sinkula commented: Thanks for clearing up some fuzz I'd left. +13
Narue 5,707 Bad Cop Team Colleague

>It recently came to my light about the functioning of a +++++ b, so I've decided to share
Thanks for sharing, but you are aware that this tidbit is irrelevant to the topic, right?

Narue 5,707 Bad Cop Team Colleague

>See also: Terminology size_t.
>And article "About size_t and ptrdiff_t".

I like how all of the references in those articles are to other articles written by the same author. :D

Narue 5,707 Bad Cop Team Colleague

>Then, how can size_t be the data type of result of the sizeof
>operator's execution, when the size of size_t is fixed, and the sizeof
>operator returns different sizes for different data types.

How can int hold all of those different values when the size is fixed on an implementation? You know what size_t is? A typedef:

typedef unsigned int size_t;

It's a synonym for whatever type the implementation chooses to fit the bill.

Narue 5,707 Bad Cop Team Colleague

>Anyone please !
You're starting to get annoying. Read the answers you've been given and try to understand them before shooting back for clarification. Your question has been answered, if you'd bother to read for comprehension. If you don't engage your brain, I'll stop trying to help you, regardless of how promising your questions are.