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

C LANGUAGE POINTER and Array

The document discusses pointers in C programming. It includes examples of declaring and accessing variables and passing their addresses to pointers. It also covers arrays, 2D arrays, printing elements and addresses, and function to print multiplication tables using arrays and pointers.

Uploaded by

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

C LANGUAGE POINTER and Array

The document discusses pointers in C programming. It includes examples of declaring and accessing variables and passing their addresses to pointers. It also covers arrays, 2D arrays, printing elements and addresses, and function to print multiplication tables using arrays and pointers.

Uploaded by

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

Exercise 3

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(){

char ptr[] = "Harry bhai";


int main(){
printf("%s", ptr);
int a=6;
return 0;
int *ptr;
}
ptr = &a;
……………………………………………
printf("The value of variable a is %d\n", a);
#include<stdio.h>
printf("The address of variable a is %u\n",
ptr);

printf("The value of variable a is %d\n", *ptr); int main(){

return 0; char s[34];

} printf("Enter your name: ");

……………………………………………………….. scanf("%s", s);

printf("Your name is %s", s);

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);
}

for(int i=0; i<n; i++){


printf("%dX%d = %d\n", num, i+1,
mulTable[i]);
}

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;
}

You might also like