C programming practice questions
C programming practice questions
Q1.
#include<stdio.h>
void fn(int *ptr) {
printf("%d\n", *ptr);
}
int main() {
int *ptr;
fn(ptr);
return 0;
}
Q2.
#include<stdio.h>
int add(int a, int b) {
int result= a + b;
}
int main() {
int result;
add(5, 10);
printf("%d\n", result);
return 0;
}
Q3.
#include<stdio.h>
int main()
{
int arr[5] = {1, 2, 3, 4, 5};
int *ptr = arr;
printf("%d\n", *(ptr + 4));
printf("%d\n", *(ptr + 6));
}
Q4.
#include<stdio.h>
void add_one(int *x)
{
*x = *x + 1;
}
void add_two(int x) {
x = x + 2;
}
int main()
{
int a = 5;
add_one(&a);
printf("value of a after add_one call %d\n", a);
add_two(a);
printf("value of a after add_two call %d\n", a);
return 0;
}
Q5.
#include<stdio.h>
int main()
{
int a = 10;
int *ptr1 = &a;
int *ptr2 = &a;
*ptr1+=1;
*ptr2+=1;
printf("%d\n", a);
}
Q6.
#include<stdio.h>
#include <stdio.h>
struct Student {
int roll_no;
char name;
float marks;
};
int main() {
Student student;
Student *ptr;
// Point the pointer to the address of the structure variable
____________
_______________
return 0;
}
Q7.
Write a program for the following requirements using structures.
Create a student structure with dno(int), subjectcodes(array of int) registered already.
When the student registers for a subject, your program will have to permit the registration only
when the student has not already registered for that subject. The student can register for
maximum of two subjects at a time.