Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
20 views

BCA_First_Sem_C_Programming_Questions

Bca 1st questions bank
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)
20 views

BCA_First_Sem_C_Programming_Questions

Bca 1st questions bank
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

BCA First Semester - C Programming Important Questions with Answers

2 Marks Questions with Answers

1. Define a variable in C.

A variable is a named memory location used to store data. Example: int x = 5;

2. What are keywords in C? Give examples.

Keywords are reserved words with special meanings. Example: int, return, if.

3. What is the difference between scanf() and printf()?

scanf() takes input, printf() displays output.

4. What is a pointer in C?

A pointer stores the memory address of another variable. Example: int *ptr;

5. Define an array in C.

An array is a collection of elements of the same type. Example: int arr[5] = {1, 2, 3, 4, 5};

5 Marks Questions with Answers

1. Explain the basic structure of a C program with an example.

Structure: Preprocessor, main(), Declarations, Statements, Return.

Example:

#include <stdio.h>

int main() {

int a = 10;

printf("Value: %d", a);

return 0;

2. Write a program to check if a number is even or odd.

Example:

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

int num;

printf("Enter a number: ");

scanf("%d", &num);

if (num % 2 == 0) printf("Even"); else printf("Odd");

return 0;

3. Explain the use of functions in C.

Functions enable modularity and reuse. Example:

void greet() { printf("Hello"); }

int main() { greet(); return 0; }

4. What is the difference between while and do-while loops?

while checks condition first; do-while runs at least once.

Example:

int i = 1; while(i<=3){printf(i);i++;}

int j = 1; do{printf(j);j++;}while(j<=3);

10 Marks Questions with Answers

1. Write a program to find the sum and average of n numbers.

Example:

#include <stdio.h>

int main() {

int n, sum=0; float avg;

printf("Enter count: ");

scanf("%d", &n);

int arr[n];

for(int i=0; i<n; i++) { scanf("%d", &arr[i]); sum+=arr[i]; }


avg=(float)sum/n;

printf("Sum=%d Avg=%.2f", sum, avg);

return 0;

2. Write a program to implement matrix addition.

Example:

#include <stdio.h>

int main() {

int a[2][2], b[2][2], sum[2][2];

for(int i=0;i<2;i++)for(int j=0;j<2;j++)scanf("%d",&a[i][j]);

for(int i=0;i<2;i++)for(int j=0;j<2;j++)scanf("%d",&b[i][j]);

for(int i=0;i<2;i++)for(int j=0;j<2;j++)sum[i][j]=a[i][j]+b[i][j];

for(int i=0;i<2;i++){for(int j=0;j<2;j++)printf("%d",sum[i][j]);printf("\n");}

return 0;

3. Explain dynamic memory allocation in C with examples.

Functions: malloc(), calloc(), realloc(), free(). Example:

#include <stdlib.h>

int *ptr = (int*)malloc(n*sizeof(int)); free(ptr);

You might also like