Click here to Skip to main content
15,891,033 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
1. char * PrintMe() {
char str[12];
strncpy (str, "hello world", 11);
str[11] = 0;
return str;
}

2. struct my_struct { int val; };
int my_func( struct my_struct *ptr, int x, int y) {
int z = 0;
if((ptr != NULL) && (x < y) || (ptr->val > 0)) {
z = x + y - ptr->val;
}
return z;
}

3. class Base {
public:
int x;
};

class Derived : public Base {
public:
int y;
};

void init(Base *b) {
for( int i = 0; i < 3; ++i) {
b[i].x = 0;
}
}

void foo() {
Derived arr[3];
init(arr);
}

What I have tried:

Let me know the bugs in the code.
Posted
Updated 13-May-18 8:10am
Comments
Mehdi Gholam 13-May-18 14:00pm    
Finding bugs is a problem for you not us here, if you have a specific problem ask a specific question.

1 solution

Homeworks are on schedule for learning some stuff. So you should use it for Learning C++. Important is also the use of the Debugger which is also explained.

There are some bugs and some smells (bad style) in the code :-O
 
Share this answer
 
Comments
[no name] 13-May-18 14:24pm    
It would be helpful if you can find the bugs here as I am new to C++.
Christian Graus 13-May-18 19:13pm    
If you're stuck, talk to your teacher. Doing your work for you is not helping, it means you don't learn

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900