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

C Programming Questions and Answers

The document provides beginner-level questions and answers about C programming, focusing on variables, operators, and arrays. It defines variables, types of variables, operators, and arrays, along with examples of code for arithmetic operations and array manipulation. Additionally, it explains the difference between int and float data types.

Uploaded by

tabrijali6
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

C Programming Questions and Answers

The document provides beginner-level questions and answers about C programming, focusing on variables, operators, and arrays. It defines variables, types of variables, operators, and arrays, along with examples of code for arithmetic operations and array manipulation. Additionally, it explains the difference between int and float data types.

Uploaded by

tabrijali6
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Beginner-Level Questions and Answers in C Programming (Variables, Operators, Arrays)

1. What is a variable in C?

A variable in C is a named memory location used to store a value. The value can be changed during

program execution.

Example:

int age = 20; // 'age' is a variable of type int storing value 20

2. What are the types of variables in C?

- int: for integers (e.g., 5, -3)

- float: for real numbers (e.g., 3.14)

- char: for single characters (e.g., 'A')

- double: for large real numbers

- void: for functions that return nothing

3. What is an operator?

An operator is a symbol that performs an operation on variables or values.

Types of Operators:

- Arithmetic: +, -, *, /, %

- Relational: ==, !=, <, >, <=, >=

- Logical: &&, ||, !

- Assignment: =, +=, -=, etc.

4. Write a program using arithmetic operators:

#include <stdio.h>

int main() {
int a = 10, b = 5;

printf("Addition: %d\n", a + b);

printf("Subtraction: %d\n", a - b);

printf("Multiplication: %d\n", a * b);

printf("Division: %d\n", a / b);

printf("Modulus: %d\n", a % b);

return 0;

5. What is a data table or array?

An array is a collection of variables of the same type stored in a contiguous memory location.

Example:

int numbers[5] = {10, 20, 30, 40, 50};

6. How to print all elements of an array?

#include <stdio.h>

int main() {

int i;

int arr[5] = {1, 2, 3, 4, 5};

for(i = 0; i < 5; i++) {

printf("Element %d = %d\n", i, arr[i]);

return 0;

7. Program to find sum of all array elements:

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

int i, sum = 0;

int arr[5] = {10, 20, 30, 40, 50};

for(i = 0; i < 5; i++) {

sum += arr[i];

printf("Sum = %d\n", sum);

return 0;

8. What is the difference between int and float?

| Data Type | Use Case | Example |

|-----------|-----------------|------------|

| int | Whole numbers | 10, -5 |

| float | Decimal numbers | 3.14, -0.9 |

You might also like