Geek Vault » 2007 » November » 09

Friday, November 9th, 2007


Uma das coisas mais básicas em programação, é a utilização de uma lista ligada para armazenar dados. O único grande problema da lista ligada, são os famigerados ponteiros.

 Ponteiros

Por incrível que pareça, ponteiros são extremamente simples, sua teoria pelo menos.
Ponteiros nada mais são do que apontadores para endereços de memória. Por exemplo, digamos que queremos uma função que receba um vetor de inteiros, altere de alguma forma, e retorne o mesmo vetor, como fazer?
Essa é uma situação bem típica, onde a utilização de ponteiros vem a calhar, vamos mostrar um código, e depois explicar aos poucos.


#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#define MAX 10
int *modifica(int *v, int n){
  unsigned int i = 0;
  for(i=0;i<n;i++){
    v[i]=10;
  }
  return v;
}
int main(void){
  int *vetor = NULL;
  if((vetor=malloc(sizeof(int)*MAX))==NULL){
    perror(”malloc”);
    return errno;
  }
  memset(vetor,’\0′,sizeof(int)*MAX);
  vetor=modifica(vetor,MAX);
  free(vetor);
  vetor=NULL;
  return 0;
}

Vamos explicar o código aos poucos. (more…)

Hello everybody, yes, I’m back with the website, now I have some code to show, and I’ll gradually explain my final thesis which I’m making for the university of Computer Science here in Mackenzie. Posts will be both in English and in Portuguese, it will depend on my mood. (Tutorials will always be in Portuguese)

Since I still have to use windows some times, this blog may be down some times, but it will be up again in no time.

Hope I can see all of your comments here.