Hi, everyone.
I'm working my way through Sam's Teach Yourself C in 21 days and I want to post my answers to the questions for your assessment. I'm not officially studying C, I'm just doing it for my own education.
1. Write the perfect Hello, world program.
Code:
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
puts("Hello, World!");
return EXIT_SUCCESS;
}
2. Give three reasons why C is the best choice of a programming language.
It's multiplatform, very widely supported, has heaps of documentation available, relatively easy to learn, can run on embedded/low-power CPUs, has standard libraries, and mature compilers.
3. What does the compiler do?
It turns my source code into object code. My compilers also turn it into an executable file. So it turns source code (my description of the program) into the actual program.
4. What are the steps in the program development cycle?
Write my code
Compile it - if it doesn't compile, fix the code and try again
Link it - if it doesn't link properly, fix the code and try again
Run the program - if it doesn't run properly, fix the code and try again
Test the program - if it doesn't do what it's supposed to, fix the code and try again
5. What command do you need to enter in order to compile a program called program1.c with your compiler?
I'm using OS X, so I can use either:
gcc program1.c
clang program1.c