Here a code example with explanation in the comments:
// First a check whether the use is logged in or not:
if ( is_user_logged_in() ) {
// The user is logged, retrieve the user id
$user_ID = get_current_user_id();
// Now we have got the user's id, we can pass it to the function 'count_user_posts':
echo 'Number of posts published by user: ' . count_user_posts( $user_ID );
} else {
// The user is not logged in
}