I have solved it by giving the parentheses, but what difference it makes?
but a problem arises again with the solution
why the 1st code is working but the second code is throwing segmentation fault(core dump)?
1st code:
Code:
using namespace std;
void count_fn(int n, int *count) {
if(n==0) {
return;
}
else {
(*count)++;
n--;
count_fn(n, count);
}
}
int main(int argc, char *argv[])
{
int count = 0;
count_fn(10, &count);
cout << endl <<"Count is" <<count << endl;
}
2nd code
Code:
#include<iostream>
using namespace std;
void count_fn(int n, int *count) {
if(n==0) {
return;
}
else {
(*count)++;
n--;
count_fn(n, count);
}
}
int main(int argc, char *argv[])
{
int *count = 0;
count_fn(10, count);
cout << endl <<"Count is" <<*count << endl;
}
how delete is used?
in the code which I posted previously, just to know the parameters used in delete and when it should be used?