C LANGUAGE POINTER and Array
C LANGUAGE POINTER and Array
POINTER
#include <stdio.h>
#include <stdlib.h>
#include<stdio.h>
int main()
int main(){
{
// char str[] = "Harry";
int i = 34;
char str[] = {'H', 'a', 'r', 'r', 'y', '\0'};
int *j = &i; // j will now store the address of i
char *ptr = str;
printf("The value of i is %d\n", i);
while(*ptr!='\0'){
printf("The value of i is %d\n", *j);
printf("%c", *ptr);
printf("The address of i is %p\n", &i);
ptr++;
printf("The address of i is %p\n", j);
}
printf("The address of j is %p\n", &j);
return 0;
return0;
}
}
……………………………..
……………………………………………………….
#include<stdio.h>
#include<stdio.h>
int main(){
return 0;
}
Exercise 3
Array #include <stdio.h>
#include<stdio.h> int main()
int main(){ {
int marks[4]; // allocate space for 4 int arr[5] = { 15, 25, 35, 45, 55 };
integers
printf("Element at arr[2]:
printf("Enter the value of marks for %d\n", arr[2]);
student 1: ");
scanf("%d", &marks[0]); printf("Element at arr[4]:
printf("Enter the value of marks for %d\n", arr[4]);
student 2: ");
scanf("%d", &marks[1]);
printf("Enter the value of marks for printf("Element at arr[0]: %d",
student 3: "); arr[0]);
scanf("%d", &marks[2]);
printf("Enter the value of marks for return 0;
student 4: "); }
scanf("%d", &marks[3]); …………………………………………
#include <stdio.h>
printf("You have entered %d %d %d and int main()
%d", marks[0], {
marks[1], marks[2], marks[3]); int arr[2][3] = { 10, 20, 30, 40, 50, 60 };
return 0; printf("2D Array:\n");
} for (int i = 0; i < 2; i++) {
……………………………………………….. for (int j = 0; j < 3; j++) {
ARRAY USING LOOP printf("%d ",arr[i][j]);
#include<stdio.h> }
printf("\n");
int main(){ }
int marks[5]; return 0;
}
for(int i=0; i<5; i++) …………………………………………………………………………
{
printf("Enter the value of marks for #include<stdio.h>
student %d: ", i+1); int main(){
scanf("%d", &marks[i]); int arr[2][3][4];
} for(int i=0;i<2;i++){
for(int j=0;j<3;j++){
for(int i=0; i<5; i++) for(int k=0;k<4;k++){
{ printf("The address of arr[%d][%d][%d]
printf("The value of marks for student is %u\n", i, j, k, &arr[i][j][k]);
%d is: %d \n", i+1, marks[i]); }
} }
return 0; }
} return 0;
…………………………………………. }
Exercise 3
…………………………………………………………………
#include<stdio.h>
void printTable(int *mulTable, int num, int n){
printf("The multiplication table of %d is :\n",
num);
for(int i=0; i<n; i++){
mulTable[i] = num*(i+1);
}
printf("*********************************
*********************\n\n");
}
int main(){
int mulTable[3][10];
printTable(mulTable[0], 2, 10);
printTable(mulTable[1], 7, 10);
printTable(mulTable[2], 9, 10);
return 0;
}