Re: problem in adding array elements
* JyotiR:
Hi.
Pls help me i have the following code which is having error.This
program is being written by Visual studio 2005
Pls help me ASAP.
OK.
#include "stdafx.h"
Non-standard header, just remove it.
Practical stuff: also remember to turn off "precompiled headers" in your Visual
Studio project settings.
void fun(int);
No need to forward-declare the function.
Just define it here.
It's the same with program text as with e.g. a technical book: always strive to
/define/ your terms (e.g. functions) before you use them.
int arr[10] = {1,2,3,4,5,6,7,8,9,10};
Global variables are ungood.
Make this local in main.
int _tmain(int argc, _TCHAR* argv[])
Non-standard.
Here's the relevant valid standard main:
int main()
{
fun(arr[0]);
return 0;
}
void fun(int *var)
This function head doesn't match the earlier forward declaration.
{
int a = *(arr[0]+2);
arr[0] produces an integer, value of 1. Adding 2 yields 3. Then attempting to
apply * to that number is in error.
int b = *(arr[0]+3);
int c;
c = a+b;
printf("\n %u",c);
}
Now the error is :
illegal indirection
See above.
Cheers, & hth.,
- Alf
--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?