ndugu,
nafikiri unahitaji ku brush kidogo C. Kifupi tu ni kuwa unapopitisha argument kama array ktk C/C++ compiler inapitisha pointer to the first element. Kwa hiyo ni kama unapitisha array of int. Pass the variables by reference if you want to modify them directly. You have just opened the can of worms!
you need to re write again. Just a note, simple program like this needs no comment. Next time just put in a code and whenever someone does not understand a line will askCode:void addConst(int& x, int& y){ //modify the x and y and they will be modified out of the function also y=y+2; x=x+5; }
just ignore the quoted post. That will work with C++ but not C. OP is right on his way of using pointers. Here is a working code
Code:#include <stdio.h> void addConst(int* , int*); int main(){ int x = 2, y = 4; printf("Before function call x = %d y = %d\n\n", x , y); printf("The function adds 3 to x and 6 to y indirectly by using the "); printf("addresses of the variables.\n"); addConst(&x, &y); printf("After function executed x = %d y = %d\n",x,y); return 0; } void addConst(int* x, int* y){ *x = *x + 3; *y = *y + 6; }
Nadhani mkuu atakuwa kapata suluisho kutoka kwa vichwa vya programming. Hii thead imeongeza afya ya ubongo wangu
papizo, feedback muhimu ili kujua post zetu zimekusaidiaje/zimekuangushaje!
Mkuu pia samahani sana kwa kuchelewa kuja kutoa majibu maana miangaiko ya hapa na pale sasa hivi ndio nimepata chance...thanks again problem ipo solved sasa hivi nashukuruni sana kwa msaada mliionyesha....
Pia kwa haraka haraka kama hauna unix ya ku compiler hiyo program unaweza kutumia hii kitu inaitwa QUINCY IDE ni ya free na unaweza kuipata hapa
Quincy: Simple free C/C++ programming IDE for Windows
iweke tu kwenye computer laptop na kazi itaanza kama itakusumbua jinsi ya kuanza kuitumia nipe shout then tutasaidia mpaka kila kitu kiwe fresh
Thanks again
Powa nimeshafanikiwa kuinstall Turbo C++. Na nilikuwa natest , ku copile na ku run prgram zote walizotoa wataalam nimeelimika sana