Papizo
JF-Expert Member
- Feb 24, 2008
- 4,944
- 1,429
Wakuu naombeni msaada wenu kugundua nini kimekosekana kwenye hii program yangu, najaribu kuicompile kutumia gcc filename -o filename but lakini naona inakubali lakini hainipi result ninazo taka mimi sasa sijui ni kwa nini au imekosekana nini.......hebu check hapa chini program yenyewe
//************************************************** *******
//point5.c - Demo of use of pointers. Pointers and functions.
//The function call passes arguments that are addresses of two variables x and y.
//The function, using the addresses of x and y modifies their content.
//The main function then displays the content of x and y.
//************************************************** ***********/
#include <stdio.h>
void addconst(int *px, int *py); // very clear function prototype
int main(void)
{
int x = 2, y = 4; //integer variables
printf("\n\npoint5.c Demo of pointers\r\n");
printf("=========================\r\n");
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\n");
printf("addresses of the variables.\n\n");
//addconst( &x, &y ); // Addresses passed to function
printf("After function executed :x = d :y = d",x,y);
return 0;
}// end of main function
//addconst
//function is passed the addresses of two variables x and y
//and then uses these addresses to alter the content of the variables
void addconst( int *px , int *py)
{
*px = *px + 3;
*py = *py + 6;
}//end of function
Hiyo ndio program yenyewe sasa hapa nime compile kwa gcc point5.c -o point then haionyeshi error alafu naweka point5 kunionyesha result,lakini majibu ninayopata hapa sio ambayo mimi ninayotaka inanipa result tofauti ambayo ni
point5.c Demo of pointers
=========================
Before function call :x = 2 :y = 4
The function adds 3 to x and 6 to y indirectly by using the
addresses of the variables.
After function executed :x = d :y = d
so hapo nilipoweka red ilibidi jibu lake liwe kama x= 5 na y=10 lakini sasa inanipa result ya x=d and y=d so not really sure where nimeenda wrong kwenye hiyo program!
Kama mnaweza kuumiza kichwa naomba kufundishwa na kukosolewa au kama kuna kitu inabidi ni add ili niweze kupata hizo result nitashukuru sana...
//************************************************** *******
//point5.c - Demo of use of pointers. Pointers and functions.
//The function call passes arguments that are addresses of two variables x and y.
//The function, using the addresses of x and y modifies their content.
//The main function then displays the content of x and y.
//************************************************** ***********/
#include <stdio.h>
void addconst(int *px, int *py); // very clear function prototype
int main(void)
{
int x = 2, y = 4; //integer variables
printf("\n\npoint5.c Demo of pointers\r\n");
printf("=========================\r\n");
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\n");
printf("addresses of the variables.\n\n");
//addconst( &x, &y ); // Addresses passed to function
printf("After function executed :x = d :y = d",x,y);
return 0;
}// end of main function
//addconst
//function is passed the addresses of two variables x and y
//and then uses these addresses to alter the content of the variables
void addconst( int *px , int *py)
{
*px = *px + 3;
*py = *py + 6;
}//end of function
Hiyo ndio program yenyewe sasa hapa nime compile kwa gcc point5.c -o point then haionyeshi error alafu naweka point5 kunionyesha result,lakini majibu ninayopata hapa sio ambayo mimi ninayotaka inanipa result tofauti ambayo ni
point5.c Demo of pointers
=========================
Before function call :x = 2 :y = 4
The function adds 3 to x and 6 to y indirectly by using the
addresses of the variables.
After function executed :x = d :y = d
so hapo nilipoweka red ilibidi jibu lake liwe kama x= 5 na y=10 lakini sasa inanipa result ya x=d and y=d so not really sure where nimeenda wrong kwenye hiyo program!
Kama mnaweza kuumiza kichwa naomba kufundishwa na kukosolewa au kama kuna kitu inabidi ni add ili niweze kupata hizo result nitashukuru sana...