Recent content by KTC
-
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...- KTC
- Post #5
- Forum: Programming and Computer Science
-
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.- KTC
- Post #7
- Forum: Programming and Computer Science
-
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...- KTC
- Post #3
- Forum: Programming and Computer Science
-
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;- KTC
- Post #15
- Forum: Programming and Computer Science
-
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.- KTC
- Post #12
- Forum: Programming and Computer Science
-
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...- KTC
- Post #10
- Forum: Programming and Computer Science
-
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...- KTC
- Post #4
- Forum: Programming and Computer Science
-
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...- KTC
- Post #2
- Forum: Programming and Computer Science
-
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...- KTC
- Post #13
- Forum: Programming and Computer Science
-
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...- KTC
- Post #26
- Forum: Programming and Computer Science
-
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).- KTC
- Post #7
- Forum: Programming and Computer Science
-
K
C/C++ 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; }- KTC
- Post #2
- Forum: Programming and Computer Science
-
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...- KTC
- Post #14
- Forum: Programming and Computer Science
-
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...- KTC
- Post #4
- Forum: Programming and Computer Science
-
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.- KTC
- Post #9
- Forum: Programming and Computer Science