Recent content by KTC

  1. K

    What this function does(i tried to trace it

    typedef struct node node; //node is alias for struct node struct node{ int value,count; node *lc,*rc; }; I would say a binary tree. Try some different examples. An empty tree, one with no left node, one with no right node, one with both...
  2. K

    C/C++ How to Fix Undefined Reference Error in C++ Matrix Constructor

    A compiler defined default constructor is provided that does a shallow copy if no default constructor is provided by the user. So the linker error wouldn't occur if the copy constructor haven't been declared at all by the user.
  3. K

    What is the meaing of this typedef line

    In C, if you want to define a struct, and later declare instances of that struct, one has to do: struct Foo { int bar; //... }; struct Foo foo_instance; Alternatively one can write: typedef struct Foo { int bar; //... } Foo_t; Foo_t foo_instance;which is equivalent to:struct Foo { int bar...
  4. K

    C/C++ Getline() Help for C++ Class: Assigning Multiple Variables from One Line of Data

    The previous line doesn't do much either, and only compile if the 3 identifier had already been declared. Valid syntax C++, get evaluated asgetline(cin, sales,','); cin; salestwo; ','; cin; salesthree;
  5. K

    C/C++ Getline() Help for C++ Class: Assigning Multiple Variables from One Line of Data

    That is true, but then one would still need to convert the string to a number.
  6. K

    C/C++ Getline() Help for C++ Class: Assigning Multiple Variables from One Line of Data

    It is not possible to do what you're wanting by calling and only calling getline() and not end up using string. getline() read into a string (the stream version read into a C-style string, while the std::string version read into a C++-style string). You either simply read in the 3 numbers using...
  7. K

    I cant understand why i get such an output?

    Let's take it one line at a time. int array[] = { 45, 67, 89 }; //1st ineAn array of int of 3 elements, with indexes from 0 to 2. So we have array[0] = 45, array[1] = 67, and array[2] = 89. int *array_ptr = &array[1]; //2nd line&array[1] is the same as &( array[1] ). So, we are...
  8. K

    Changing the address of a pointer question

    Um, don't do that! string, or more precisely std::string is a C++ standard library string, which has its own various operators like assignment. char* strcpy( char *to, const char *from ) is a C (and C++) function that copy the C-style string (null terminated char arrays) pointed to by from to...
  9. K

    What is the Correct Way to Use Pointers in C?

    double (*y)(double);is a pointer to a function, the pointer identifier (the name of the pointer variable) is y. It is a pointer to a function that take one parameter, of type double, with a return type of double. Since sin from <math.h> has that signutaredouble sin( double arg );, we can...
  10. K

    How Can I Fix My C While Loop Issue in Calculating Factorials?

    You're either coding to C90, in which case you can drop the "int" in front of main(void), but you'll have to explicitly specify a return value; or C99, in which case you have to have the "int" in front of main(void), but can let the return value be implicit; or C++, where you don't need the...
  11. K

    How Can I Fix My C While Loop Issue in Calculating Factorials?

    x > 100means precisely what it suggest, x is greater than 100. And || is OR, I think you were wanting && (AND).
  12. K

    Creating a Function Prototype in C++ to Calculate a Value Using f(x)

    There's nothing wrong with what you have. #include <iostream> #include <math> double f(double x) { return 5*std::pow(x,3) - 3*std::pow(x,2) + 2*x + 1; } int main() { std::cout << f(2.4) << std::endl; }
  13. K

    How to Fix the 'main' Must Return 'int' Error in C Programming

    No no no. One, most of the compilers that exist code to C90, which doesn't specify the implementation-defined bit that article you linked to say. but some provide void main() as a compiler extension anyway. In C99, you already saw That mean, yes, the compiler is allowed to let you write...
  14. K

    Subfunctions returning different types together (in C)

    Look at the code I posted. The definition of calculate explicitly called sum() & divide(). Which um, I just realized is a problem as sum is a int variable, and not the name of your function. But anyhow, yes the function suppose to call two different function and assigned their respective return...
  15. K

    How to Fix the 'main' Must Return 'int' Error in C Programming

    Well, it's not really just C99. C has always required main() to return int. Confusion arise as old C allow one to write main(void)i.e. with no return type. At the time, a function declaration with no explicit return type return an int implicitly.
Back
Top