Output of this Programme please??main(){ int a[]={2,4,6,8,10}; int i;change(a,5);for(int i=0;i

Showing Answers 1 - 13 of 13 Answers

I think the syntax is incorect in the for loop of the change function, it sould have atleast a closing ')'.

Secondly, if the function defination is given after the function calling, then the proper prototype of the function must be declared before the calling of the function, other wise compiler declares a default prototype by considering each parameters as well as the return type as integer, which leads into the compiler error "type mismatch in redeclaration of the function".

  Was this answer useful?  Yes

Ravi Bhsuhan Raiya

  • May 2nd, 2006
 

In this program, we have syntax error in function (change). the for loop is not properly ended.

  Was this answer useful?  Yes

Mitul Surti

  • May 31st, 2006
 

dude the pointer declarations are allllll fine coz *(b+i) is equivalent to b[ i ]wats wrong is1) the for loop declaration for sure2) by default functions return value is int, hence your function should return a value else it hsould be declared void explicitly

  Was this answer useful?  Yes

mitul surti

  • May 31st, 2006
 

well all the pointer declarations are perfectly OK coz *( b + i ) is equivalent to b[ i ]well 2 things are wrong about d prog1) for loop declaration2) by default the returntype of a function is int..hence as the function does not return type..it should be explicitly declared as void ..as it is considered int by default..and will return a compile time error

  Was this answer useful?  Yes

taransidhu

  • Jun 1st, 2006
 

ok if we ignore some syntax mistakes than the purpose of the function is to add 5 to each element of aaray as we are passing addresses of each element any change in value of array elements in function will be reflected in main also

 as mr Mitul Surti has told already that *(b+i) is equivalent to b[ i ]so

*(b+i) = *(b+i)+5;  means

b[ i ]=b[ i ]+5;

umesh936

  • Sep 7th, 2006
 

for(i=0;i *(b+i) = *(b+i)+5;

see the statement

can any body tell me what i*(b+i) means

*(b+i) = b[i] : i agree

bt i*(b+i)=ib[i]

wht does it mean?

2nd reason )offcourse for loop is not properly ended

  Was this answer useful?  Yes

gpreddy

  • Nov 8th, 2006
 

The error is in int i;for(int i=0;i<=4;i++)here i declared twice : the remaining errors are may be typo errors.

  Was this answer useful?  Yes

chaitanya

  • Oct 21st, 2007
 

First lets get the code ryt..

#include "stdio.h"


void change(int *b,int n)
{
  int i;
  for(i=0;i   *(b+i) = *(b+i)+5;
}


int main()
{
 
  int a[]={2,4,6,8,10};
  int j;
  change(a,5);
  for(j=0;j<=4;j++)
    printf("n %d",a[j]);
 return 0;
}

may be the question was asked to test the return values in the calle function rather than syntax errors, so this program does reflect the added 5 to the array since its pass by reference rather than a pass by value.

hope it helps,

chaitanya gudipati

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions