Daniele°
/c_gcc #include<stdio.h> void foo(char** ch){ **ch = 'b'; } int main(){ char z = 'a'; char* k = &z; foo(&k); printf("%c",z); return 0; }
Daniele°
Result: b
Daniele°
In C the you need to read from right to left char * lol; lol is pointer to char char const * lol; lol is pointer to const char char * const lol; lol is const pointer to char char const * const lol; lol is const pointer ti const char
Francesco
but this work also with a simple pointer
Francesco
Yes
So malloc for my example was needed. I want show how ** can have affect on the pointer
Dima
why would you need pointer to pointer
Francesco
it isn't a good code, sure. I want only underline that
Francesco
Francesco
why would you need pointer to pointer
if you want a matrix with dimension chose at runtime for example, or if you want change a pointer location as my (bad) code
Dima
Well, there are better methods to implement that
НОЗИМ
#include <iostream> #include <conio.h> using namespace std; bool gameover; const int width = 20; const int height = 20; int x, y, fruitx, fruity, score; int tailx[100], taily[100]; int nTail; enum edirection{ STOP = 0, LEFT, RIGHT, UP, DOWN }; edirection dir; void setup(){ gameover = false; dir = STOP; x = width / 2 - 1; y = height / 2 - 1; fruitx = rand() % width; fruity = rand() % height; score = 0; } void draw(){ system("cls");// system ("clear"); for (int i = 0; i < width + 1; i++) cout « "#"; cout « endl; for (int i = 0; i<height; i++){ for (int j = 0; j<width; j++){ if (j == 0 || j == width - 1) cout « "#"; if (i == y&& j == x) cout « "0"; else if (i == fruity&&j == fruitx) cout « "f"; else{ bool print = false; for (int k = 0; k < nTail; k++){ if (tailx[k] == j && taily[k] == i){ print = true; cout « "o"; } } if (!print) cout « " "; } } cout « endl; } for (int i = 0; i < width + 1; i++) cout « "#"; cout « endl; cout « "score:" « score « endl; cout « "DASTURCHI:ELYOR NOSIROV" « endl; } void input(){ if (_kbhit()){ switch (_getch()){ case'a': dir = LEFT; break; case'd': dir = RIGHT; break; case'w': dir = UP; break; case's': dir = DOWN; break; case'x': gameover = true; break; } } } void Logic(){ int prevx = tailx[0]; int prevy = taily[0]; int prev2x, prev2y; tailx[0] = x; taily[0] = y; for (int i = 1; i < nTail; i++){ prev2x = tailx[i]; prev2y = taily[i]; tailx[i] = prevx; taily[i] = prevy; prevx = prev2x; prevy = prev2y; } switch (dir) { case LEFT: x--; break; case RIGHT: x++; break; case UP: y--; break; case DOWN: y++; break; } if (x >= width - 1) x = 0; else if (x < 0) x = width - 2; if (y >= height) y = 0; else if (y < 0) y = height - 1; for (int i = 0; i < nTail; i++){ if (tailx[i] == x&&taily[i] == y) gameover = true; } if (x == fruitx&&y == fruity){ score += 10; fruitx = rand() % width; fruity = rand() % height; nTail++; } } int main(){ setup(); while (!gameover){ draw(); input(); Logic(); } return 0; }
НОЗИМ
this is snake game
НОЗИМ
НОЗИМ
good or ??
Anonymous
Where is snake?
НОЗИМ
in picture
НОЗИМ
НОЗИМ
guys share your projects
НОЗИМ
say your opinion
Anonymous
say your opinion
O'yinni qayerdan olsak bo'ladi?
НОЗИМ
НОЗИМ
arzimaydi
Anonymous
arzimaydi
Raxmat..
Anonymous
enum edirection{ STOP = 0, LEFT, RIGHT, UP, DOWN }; = 0 redundant.
Anonymous
Beta rejimda?
Anonymous
Yo'qmi?
Anonymous
system("cls");// system ("clear"); Be portable! Use preprocessor to select command depending on platform (it's still better to not use shell commands at all).
Anonymous
Yeah, I see.
Francesco
conio.h is not portable
Anonymous
Someone in this group have programed in gcrypt? xd
Anonymous
Can't compile on my linux system(
Francesco
system("cls");// system ("clear"); Be portable! Use preprocessor to select command depending on platform (it's still better to not use shell commands at all).
with preprocessor directives can choose if use conio.h or ncurses for compatibility with linux and windows
Anonymous
https://stackoverflow.com/questions/7469139/what-is-equivalent-to-getch-getche-in-linux#7469410 But I'm not sure about _kbhit() replacement.
НОЗИМ
this code i saw in videolesson and has written i want yo hear errors
НОЗИМ
what belongings possible to create on with c++
НОЗИМ
where you study
НОЗИМ
good night everybody
Anonymous
Or to dynamically allocate a matrix Where p** = array of * (that are arrays them self)
Can you explain me like I am 5 , what's dynamic allocation
Anonymous
And how double pointer is helpful in that case
Francesco
Can you explain me like I am 5 , what's dynamic allocation
https://stackoverflow.com/questions/1403150/how-do-you-dynamically-allocate-a-matrix
many
What does it mean?
Andrea
Error
Anonymous
Error
Are you working for any project based on c
Daniele°
Anonymous
HELLO group . I come
Anonymous
happy new year soon....
Anonymous
you will best year and you luky yet!!!!!!!
Anonymous
Anonymous
Anonymous
Hey
Anonymous
Guys !
Anonymous
Anyone online here ?
h4child
me
Anonymous
So
Anonymous
Do you know how to code in c or c++ ?
Anonymous
Yeah
harry
hello
Anonymous
Hey
Anonymous
What is up ?
Anonymous
Can u recommend any beneficial books to learn C programming language ?
Anonymous
I am kinda confused here
harry
k&r, I suppose
Anonymous
What does it stand for ?
Anonymous
K & r
harry
kernighan and richie "the c programming language"
harry
no guarantees for the spelling
Anonymous
Do u have the e version of this book ?