Francesco Gadaleta

My life style, my interests, my thoughts. Just my personal stuff.

const pointer vs. pointer to const

Bookmark on:      


/*
ex. usage of a constant pointer to a (variable integer)
ex. how to fuck a pointer to a constant variable

*/
#include

int main(void)
{
const int c=0;
// constant pointer to a (variable) integer: can change the value of the var but not the pointer
int* const ptr1 = malloc(sizeof(int));
*ptr1 = 10;
*ptr1 = 100;

int t;
// pointer to a constant integer: can change the pointer but not the variable
const int* ptr2 = malloc (sizeof(int));
int modvar = 10;

ptr2 = &modvar;
modvar = 100;

printf(”%d\n”, *ptr2);
return 0;
}






About this entry

You’re currently reading “const pointer vs. pointer to const,” an entry on Francesco Gadaleta

Published:
27.06.08 / 10pm
Category:
Computer Science

Comments are closed

Comments are currently closed on this entry.

Comments are closed.


Pages

  • Contacts
  • Extras
    • Appunti di Ing.Informatica(Polimi)
    • Materials for the History of Computing
  • Geek infos
  • Personal Infos
  • Photo Gallery

Recently

  • 28.06 PhotoArt web site
  • 27.06 const pointer vs. pointer to const
  • 11.06 Cerchi lavoro?
  • 28.04 A day without glasses
  • 09.04 Google Viral Infection
  • 08.02 Coming back to reality
  • 16.01 Capodanno a Berlino
  • 22.12 Altrove…
  • 19.12 A four-day-trip in London
  • 01.12 30 Novembre 2007

Categories

  • Computer Science (9)
  • Fotografia (6)
  • Humour (7)
  • News from Leuven (10)
  • Opensource (1)
  • Politica e società (9)
  • Progetti (6)
  • Tutorials (9)
  • Uncategorized (1)
  • Computer Science

    • Citeseer
    • Eric Raymond
    • Mccallum home page
    • semantic web
  • Personal Links

    • Gadaleta photography
    • Light Painting
    • Studio Minotti
  • Politics

    • Archivio Noam Chomsky
    • Beppe Grillo
    • Megachip
    • Noam Chomsky
  • Friends

    • EtextNet
    • FreeRide Soul
    • Gek’o Pub Milano
    • Stefano Galli
    • Training Days

Powered by Hemingway flavored Wordpress.

Entries RSS Comments RSS