0% found this document useful (0 votes)
18 views

Intro Programming

Uploaded by

royalcommunity43
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views

Intro Programming

Uploaded by

royalcommunity43
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 16

Lets..

Intro
Programming
What is the programming?
Imagine programming as giving instructions to a robot,
but instead of using words, you use a special language
that the robot understands. This language is made up
of specific commands and words that tell the robot
exactly what to do, step-by-step.

there are some key things to remember about


programming:

 It's about giving instructions: Programming


is all about writing clear and concise
instructions that the computer can
understand and follow.
 It's like speaking another language: Just like
you wouldn't speak Spanish to a French
person, you wouldn't use Python code to tell
a Java program what to do. Different
programming languages have different rules
and syntax.
 It's used to create all sorts of things: From
the websites you visit to the apps you use on
your phone, everything you see and interact
with on a computer is likely the result of
programming.

No
w, let's break down the key components of
programming:

1.Data: This is the information that your


program will work with. It can be
numbers, text, images, or even other
programs!
2.Instructions: These are the commands that
tell your program what to do with the
data. They can be simple things like adding
two numbers together or more complex
things like sorting a list of names.
3. Logic: This is the way your program makes
decisions. For example, you might use an if
statement to tell your program to do one thing if
it's raining and another thing if it's sunny.
4. Loops: These are like repeat signs in music. They
tell your program to do the same thing over and
over again until a certain condition is met.

What is the IDE :

An IDE, or Integrated Development Environment, is


basically your programming kitchen. It's where you
gather all the ingredients (your code), tools (compilers,
debuggers etc.), and recipes (libraries, frameworks) you
need to cook up a delicious program!

Here's a quick breakdown of the main functions of an


IDE, in kitchen terms:

 Editor: Your main workspace, like a spacious


counter, where you write your code (mix the
ingredients).
 Compiler: Checks your code for errors, like making
sure you haven't forgotten any essential
ingredients.
 Debugger: Helps you identify and fix any bugs in
your program, like figuring out why your cake didn't
rise properly.
 Runner: Executes your program, like putting your
cake in the oven to bake.
 Libraries and frameworks: Pre-written code
snippets you can add to your program, like having
pre-chopped veggies or pre-measured flour to save
time.

What is the Complier ?

1. Translator: You give the compiler your code (in a


specific programming language, like "French"
code), and it meticulously translates it into machine
code, which is the only language your computer
understands (like "English" instructions for the
oven).
2. Baker: Once the code is translated, the compiler
actually bakes your program, turning it into an
executable file – the final cake ready to be enjoyed!

Here's a simpler breakdown:

 You write your code (recipe) in a human-readable


language.
 The compiler reads your code and translates it into
machine code (oven instructions).
 The machine code tells your computer exactly what
to do to run your program (bake the cake).

What is the C Programming ?

What is C?

 It's a language you can use to talk to computers and tell


them what to do.
 It's like a secret code between you and the computer!
 It's one of the oldest and most popular programming
languages, like the grandpa of code!

Why learn C?

 It's like learning the basics of music before playing an


instrument.
 It'll help you understand how computers think and work.
 It's a foundation for learning other programming languages
more easily.
 It's like learning to drive a stick shift – once you know it, you
can drive anything![

How does it work?

1. You write instructions (code) in C. ✍️a


2. The compiler translates those instructions into a language
the computer understands (machine code).
3. The computer follows those instructions to do what you
want!
Lets go your First C program

#include <stdio.h>

int main() {
printf("Hello, world!\n");
}

#include <stdio.h>

 Meaning: This line brings in a special file called


"stdio.h" (standard input/output header), which
contains tools for printing messages to the screen
and getting input from the user. It's like adding a
toolbox for communication!

2. int main() {

 Meaning: This 4line marks the beginning of the


main part of your program, where the action
happens. It's like opening the door to your code's
house!

3. printf("Hello, world!\n");

 Meaning: This line prints the message


"Hello, world!" to the screen, followed by a newline
character (\n) to move the cursor to the next
line. It's like saying "hello" to the world through
your code!

4. return 0;
 Meaning: This line tells the computer that the
program has finished successfully. It's like giving a
thumbs up to say "all good!"

5. }

 Meaning: This line closes the main part of your


program, like closing the door of the code house.

Lets Understands Printf() & Scanf()

The printf() and scanf() functions are used for


input and output in C language. Both functions
are inbuilt library functions, defined in stdio.h
(header file).

scanf() function
The scanf() function is used for input. It reads the input data from the
console.

Just Simple Example

#include <stdio.h>
int main() {

int num;

printf("Enter the Any Number");


scanf("%d" ,0& num);

Compilation process in c
What is a compilation?
The compilation is a process of converting
the source code into object code. It is done
with the help of the compiler. The compiler
checks the source code for the syntactical
or structural errors, and if the source code
is error-free, then it generates the object
code.
What is the Variables

Imagine variables as labeled boxes that store different


types of information in your program.

Key points:

 Declaring variables: You create a variable using a


specific data type and a name, like labelling a box.
 Storing values: You can put different values into
these boxes to keep track of things in your
program.
 Using variables: You can use the values stored in
variables to perform calculations, make
decisions, and create output.

Basic data types:

 int: Stores whole numbers (e.g., 42, -15, 0). Think


of it as a box for integers.
 float: Stores numbers with decimals (e.g., 3.14, -
2.5). It's like a box for floating-point numbers.
 char: Stores a single character
(e.g., 'A', 'z', '#'). Imagine a box just big enough for
one letter or symbol.
Data type in C programming ?

1. int (Integers):

o Like a box for whole numbers (no decimals).


o Examples: 10, -5, 0, 42
o Use it for counting things, storing ages, or
representing scores.
2. float (Floating-point numbers):

o Like a jar for numbers with decimals.


o Examples: 3.14, 2.5, -1.234
o Use it for measuring things like
temperature, distance, or money.
3. char (Characters):
o Like an envelope for a single letter, symbol, or digit.
o Examples: 'A', 'z', '#', '5'
o Use it for storing individual characters, like initials or
passwords.

double (Double-precision floating-point)

 Shape: A larger container for even more precise decimal


numbers, like a scientific measuring cup.
 Examples: 3.1415926535, 1.234e-5 (scientific notation)
 When to use: Handling very large or very small numbers, or
calculations requiring high precision

Some Given Simple Example

int age = 25;


float pi = 3.14159;
char initial = 'M';
double distance = 123456789.123456;
What is the Format Specifier in C
programming ?
Imagine format specifiers as special codes that
tell the computer exactly how to display or read
different types of data, similar to using specific
symbols for different types of ingredients in a
recipe.

Key points:

 Used in printf() and scanf() functions: These functions


handle input and output in C, and format specifiers
are essential for them to work correctly.
 Each data type has its own specifier: Just like you
wouldn't use the same symbol for flour and eggs,
each type of data needs a specific format specifier.

Common Format Specifiers in C Programming:

 int: %d
 float: %f
 char: %c
 string: %s

Additional Notes:

 double: %lf (for double-precision floating-point


numbers)
 long int: %ld (for long integers)
 long long int: %lld (for very large integers)

Remember:

 Use format specifiers within printf() to format output


and scanf() to read input.
 Match the specifier to the data type for correct
results.
 Explore additional specifiers for more control over
formatting.

Lets go on Simple Example of


Format Specifier
#include <stdio.h>

int main() {
int age;
float height;
char initial;
char name[50];

printf("Enter your age: ");


scanf("%d", &age);

printf("Enter your height in meters: ");


scanf("%f", &height);

printf("Enter your initial: ");


scanf(" %c", &initial); // Note the space before %c to consume any
extra newline

printf("Enter your full name: ");


scanf("%s", name);

printf("\nYou entered:\n");
printf("Age: %d\n", age);
printf("Height: %.2f meters\n", height);
printf("Initial: %c\n", initial);
printf("Name: %s\n", name);

return 0;
}
Some Practices Session
 Write a c program Age Calculator:
 Write a C program Add two Number And Display
result on Sum Variable
 Write a c program Calculate of Area of Rectangle
 Write A c program Calculate Area of Rectangular

Interview Questions

1.What is a data type in C?

A data type in C is a classification that specifies


which type of value a variable can hold. It defines
the type of data a variable can store, such as int,
float, char, etc.
2 Differentiate between 'int' and 'float' data types
in C. ?

The 'int' data type is used for integer values, while


the 'float' data type is used for floating-point
(decimal) values.
Explain the significance of the 'sizeof' operator in
C.

3 What is the range of values for an 'int' data


type in C?

The range of values for an 'int' data type in C is


typically from -32768 to 32767 for a 16-bit system
and -2147483648 to 2147483647 for a 32-bit
system.
4 How is a 'char' data type different from an
'int' data type?

The 'char' data type in C is used to store single


characters, while the 'int' data type is used for
integers (whole numbers).

5 What is the purpose of the 'const' keyword


in C when declaring variables?

The 'const' keyword in C is used to declare


constants. Once a variable is declared with 'const,'
its value cannot be changed during program
execution.

Explain the concept of signed and unsigned


integers in C. ?

In C, 'signed' integers can represent both positive


and negative values, while 'unsigned' integers can
only represent non-negative values (zero and
positive integers).

How are local variables different from global


variables in C?

Local variables are declared within a function or


block and have local scope, meaning they are
accessible only within that function or block. Global
variables, on the other hand, have a global scope
and can be accessed throughout the entire
program.

You might also like