You can make use of this constant called ABSPATH in other places of your wordpress scripts and in most cases it should point to your wordpress root directory.
Note: This answer is really old and things may have changed in WordPress land since.
I am guessing that you need to detect the WordPress root from your plugin or theme.
I use the following code in FireStats to detect the root WordPress directory where FireStats is installed a a WordPress plugin.
For retrieving the path you can use a function <?php $path = get_home_path(); ?>. I do not want to just repeat what had been already said here, but I want to add one more thing:
If you are using windows server, which is rare case for WordPress installation, but still happens sometimes, you might face a problem with the path output. It might miss a "\" somewhere and you will get an error if you will be using such a path. So when outputting make sure to sanitize the path:
<?php
$path = get_home_path();
$path = wp_normalize_path ($path);
// now $path is ready to be used :)
?>
I like @Omry Yadan's solution but I think it can be improved upon to use a loop in case you want to continue traversing up the directory tree until you find where wp-config.php actually lives. Of course, if you don't find it and end up in the server's root then all is lost and we return a sane value (false).