0
0
Cprogramming~15 mins

Variable declaration and initialization - Mini Project: Build & Apply

Choose your learning style9 modes available
Variable declaration and initialization
📖 Scenario: You are creating a simple program to store and display information about a book.
🎯 Goal: Learn how to declare variables and assign values to them in C.
📋 What You'll Learn
Declare variables with correct types
Initialize variables with given values
Print variable values
💡 Why This Matters
🌍 Real World
Storing and displaying information about objects like books is common in many programs.
💼 Career
Understanding how to declare and initialize variables is a fundamental skill for any C programmer.
Progress0 / 4 steps
1
Declare variables for book information
Declare a variable called title of type char array with size 50, and a variable called pages of type int.
C
Need a hint?

Use char title[50]; to declare a string variable and int pages; for the number of pages.

2
Initialize variables with values
Initialize the variable title with the string "C Programming" using strcpy, and initialize pages with the value 250. Include #include <string.h> at the top.
C
Need a hint?

Use strcpy(title, "C Programming"); to copy the string and pages = 250; to assign the number.

3
Add a variable for price
Declare a variable called price of type float and initialize it with the value 29.99.
C
Need a hint?

Use float price; to declare and price = 29.99f; to initialize.

4
Print the book information
Use printf to display the book information in this format: Title: C Programming, Pages: 250, Price: $29.99.
C
Need a hint?

Use printf("Title: %s, Pages: %d, Price: $%.2f\n", title, pages, price); to print the values.