Da C a Java
Concetti base
Punti chiave
- Concetti base di programmazione
- flusso di esecuzione
- variabili tipizate
- strutture dati elementari
- Scoping
- Concetto di Funzione
- Puntatori
- stack
- heap
- Passaggio di Parametri
Scoping
Globale
#include <stdio.h>
int life = 42;
int main( int argc, char** argv ){
printf("The answer to the ultimate question of life, the universe and everything is %d", life);
return 0;
}
Locale
#include <stdio.h>
int main( int argc, char** argv ){
int life = 42;
printf("The answer to the ultimate question of life, the universe and everything is %d", life);
return 0;
}
Concetto di Funzione
#include <stdio.h>
void uslessFunction(){
printf("Do nothing...");
}
int life(){
return 42;
}
int main( int argc, char** argv ){
uslessFunction();
printf("The answer to the ultimate question of life, the universe and everything is %d", life() );
return 0;
}
Puntatori
Puntatore ad una variabile
#include <stdio.h>
int main( int argc, char** argv ){
int life = 42;
int* pointer = &life;
return 0;
}
Creare un puntatore
#include <stdio.h>
#include <stdlib.h>
int main( int argc, char** argv ){
int* life = malloc(sizeof(int));
return 0;
}
Passaggio di Parametri
Valore
#include <stdio.h>
void f( int a ){
a++;
}
int main( int argc, char** argv ){
int life = 42;
f(a);
printf("Life is still %d",life);
return 0;
}
Riferimento
#include <stdio.h>
void f( int* a ){
a++;
}
int main( int argc, char** argv ){
int life = 42;
f(&a);
printf("Life is not 42 but %d",life);
return 0;
}
Ends
andrea.ghz@gmail.com
andreaghizzoni.github.io
@_ghzz
From C to Java
By AndreaGhizzoni
From C to Java
- 530