Jump to content

Pointer Inquiry

- - - - -

  • Please log in to reply
5 replies to this topic

#1
espdev-darkness

espdev-darkness

    Learning Programmer

  • Members
  • PipPipPip
  • 44 posts
Hey guys, I was reading my C++ book when I came across the chapter on pointers. When I heard they point to the memory adress in which a variable is stored my heart lept for joy. You see Im very intrigued by the unexpected potentials of programming languages. If you look at the code below you will see my potential idea for a program that could crash a computer in a matter of seconds.

// Memory Re-write program


#include <iostream>


using namespace std;


int main()

{

	int initialAdress = 1;

	int* pointer = &initialAdress;


	while(true) // I have no intention of breaking this loop

	{

		pointer += 1;

		*pointer = 1337;

	}


               return 0;

}




Basicly what this program does is increase the actual memory adress that the pointer is pointing at by 1. I'm assuming this would give it a random memory adress. From here I assign that memory adress to the value 1 ( correct me if im not stating this properly). This continues forever, well until the computer crashes due to overwriting an important adress in memory. Please do not think Im some sort of script kiddie looking to crash computers, I'm not I just want to understand the language and its strange capabilities better.

#2
Guest

Guest

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 3,414 posts
You aren't going to crash anything. If a program tries to write memory that it isn't supposed to, the operating system will give a segmentation fault.
Root Beer == System Administrator's Beer
Download the new operating system programming kit! (some assembly required)

#3
Alexander

Alexander

    It's Science!

  • Moderators
  • 4,118 posts
  • Location:Vancouver, Eh! Cleverness: 200
What do you mean by strange capability? Do you understand C requires this low level access to do anything complex?
Be sure to read the updated FAQ! || Health is achieved through the same 10,000 steps.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.

#4
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
  • Location:Upstate, South Carolina
  • Programming Language:C, C++, PL/SQL, Delphi/Object Pascal, Pascal, Transact-SQL, Others
  • Learning:Java, C#, PHP, JavaScript, Lisp, Fortran, Haskell, Others
I did something similar with BASIC in the old days of MS-DOS. It crashed the OS. Modern OS's do NOT let you do that, however.
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#5
mebob

mebob

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 490 posts
You can't crash it because modern OS's run in something called "Protected Mode". Basically, when the OS is booting up, it makes a bunch of descriptors that tell the CPU what the memory limits for each program is, then loads this in to the processor. It's actually more complex than this, but this is a simple explanation.
Latinamne loqueris?

#6
espdev-darkness

espdev-darkness

    Learning Programmer

  • Members
  • PipPipPip
  • 44 posts
Wow, thanks for all the help understanding this. This just goes to show how much I have to learn.




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users