Sample Solution from
C Programming Language
2nd Edition
ISBN: 9780131103627
Chapter 1
Problem 1E
Try another sample solution
Textbook Problem

Run the “hello, world” program on your system. Experiment with leaving out parts of the program, to see what error messages you get.

Expert Solution
Program Plan Intro

To run the hello world program and experiment with leaving out parts of the hello world program, to see the error message.

Explanation of Solution

Program:

//Leaving out header file
//#include <stdio.h>
main()
{
printf("Hello, ");
	printf("World");
printf("\n");
}

Explanation:

The program above leaving the header file <stdio.h> statement to see the error. There is a warning in the program and shows the output.

Sample Output:

Program: 

#include <stdio.h>
//Leaving out main function
//main()
{
printf("Hello, ");
	printf("World");
printf("\n");
}

Explanation:

The program above leaving the main function to see the error. There is an error in program line 4.

Sample Output:

Program: 

#include <stdio.h>
main()
{
//Leaving out first statement line
//printf("Hello, ");
	printf("World");
printf("\n");
}

Explanation:

The program above leaving the first statement line to see the error. There is no error and print world, then a new line.

Sample Output:

Program: 

#include <stdio.h>
main()
{
printf("Hello, ");
//Leaving out second statement line
	//printf("World");
printf("\n");
}

Explanation:

The program above leaving the second statement line to see the error. There is no error and print hello, then a new line.

Sample Output:

Program: 

#include <stdio.h>
main()
{
printf("Hello, ");
	printf("World");
	//Leaving out third statement line
//printf("\n");
}

Explanation:

The program above leaving the third statement line to see the error. There is no error and print hello,world without a new line.

Sample Output:

Program: 

#include <stdio.h>
//Leaving out curley braces.

main()
//{
printf("Hello, ");
printf("World");
printf("\n");
//}

Explanation:

On leaving the curly braces the program will not compile and produce compilation error.

Sample Output:

Not sold yet?Try another sample solution