;#include <stdio.h>
int main()
{
int x=10;
int *p;
p=&x;
printf("x=%d\n",x);
printf("%u",&x);
printf("%d",*(&x));
printf("%d",*p);
return 0;
}
#include<stdio.h>
int main(){
int x=20;
int* p =&x;
int **q=&p;
printf("Value of x is %d\n",x); // 10
printf("Address of x is %p\n",&x); // 100
printf("%p\n",p); // 10
printf("%u\n",&p); // 10
printf("%u\n",q);
printf("%u\n",*q);
printf("%d\n",**q);
return 0;
}
Output
Value of x is 20
Address of x is 0x7ffe080aa024
0x7ffe080aa024
134914088
134914088 134914084
20
Swaping
#include <stdio.h>
void swap(int* , int*);// we pass the address of the integer save in the integer variable
int main()
{
int a =10,b=20;
swap(&a,&b);
printf("a= %d,b=%d",a,b);
return 0;
}
void swap(int *p, int *q)
{
int temp;
temp=*p;
*p=*q;
*q=temp;
}
array find the largest number.
#include<stdio.h>
int main(){
int arr[6];
printf("Enter any numbers:- ");
for(int i=0;i<6;i++){
scanf("%d",&arr[i]);
}
int max=arr[0];
int min=arr[0];
for(int i=0;i<6;i++){
if(max<arr[i]){
max=arr[i];
}
if(min>arr[i]){
min=arr[i];
}
}
printf("The largest element of the array is:-%d\n",max);
printf("The smallest element of the array is:-%d\n",min);
return 0;
}
Output
Enter any 6 numbers: - 2 24 3 5 5 5
largest number-24
Smallest Number-2
USing Function with array find the largest Number
#include<stdio.h>
# define MAXI 5
void input(int* , int);
int max(int* ,int);
void output(int*, int);
void input(int* x,int n){
printf("Enter %d element in array",n);
for(int i=0;i<n;i++){
scanf("%d",&x[i]);
}
}
int max(int* x,int n){
int max=x[0];
for(int i=0;i<n;i++){
if(max<x[i]){
max=x[i];
}
}
return max;
}
void output(int* x,int n){
printf("%d Enter the Element in array",n);
for(int i=0;i<n;i++){
printf("%d ",x[i]);
}
printf("\n");
}
int main(){
int arr[MAXI];
int k;
printf("Enter the size of array :- ");
scanf("%d",&k);
input(arr,k);
output(arr,k);
printf("Maximun element in array is %d \n",max(arr,k));
return 0;
}
Output
Enter the size of array :- 3
Enter element in array32 1 13
Enter the Element in array 32 1 13 Maximun element in array is 13
TRILOK SIR
Run in a Turbo C
#include <stdio.h>
// int main()
// {
// int a;
// printf("enter a number");
scanf("%u",&a);
printf("a=%d",a);
}
#include <stdio.h>
int main() {
// int a=3;
// int p;
// int q;
// p-&a;
// q-a;
// int a=3,i=0;
// i= a++* a++* a++;
// printf("i=%d a=%d",i,a);
//char ch[]="GATE2024"; char *p=ch; printf("%s",p+p[3]-p[1]);
=> 1000+E-A
=> 1000 + 69 -65 (A and E are ASSIC VALUE)
=> 1000 + 4
1004 so it started with 2004 because the 2 have a base address is 1004
// int a =300,i=0;
// i=a*a/a;
// printf("%d",i);
return 0; }
Program for Stack in C [Push, Pop, Display]
#include<stdio.h>
#define MAX 5 //Maximum number of elements that can be stored
int top=-1,stack[MAX];
void push();
void pop();
void display();
void main()
{
int ch;
while(1) //infinite loop, will end when choice will be 4
{
printf("\n*** Stack Menu ***");
printf("\n\n1.Push\n2.Pop\n3.Display\n4.Exit");
printf("\n\nEnter your choice(1-4):");
scanf("%d",&ch);
switch(ch)
{
case 1: push();
break;
case 2: pop();
break;
case 3: display();
break;
case 4: exit(0);
default: printf("\nWrong Choice!!");
}
}
}
void push()
{
int val;
if(top==MAX-1)
{
printf("\nStack is full!!");
}
else
{
printf("\nEnter element to push:");
scanf("%d",&val);
top=top+1;
stack[top]=val;
}
}
void pop()
{
if(top==-1)
{
printf("\nStack is empty!!");
}
else
{
printf("\nDeleted element is %d",stack[top]);
top=top-1;
}
}
void display()
{
int i;
if(top==-1)
{
printf("\nStack is empty!!");
}
else
{
printf("\nStack is...\n");
for(i=top;i>=0;--i)
printf("%d\n",stack[i]);
}
}
Output:
\** Stack Menu ****
1.Push
2.Pop
3.Display
4.Exit
Enter your choice(1-4):1
Enter element to push:3
\** Stack Menu ****
1.Push
2.Pop
3.Display
4.Exit
Enter your choice(1-4):1
Enter element to push:6
\** Stack Menu ****
1.Push
2.Pop
3.Display
4.Exit
Enter your choice(1-4):2
Deleted element is 6
\** Stack Menu ****
1.Push
2.Pop
3.Display
4.Exit
Enter your choice(1-4):3
Stack is…
3
\** Stack Menu ****
1.Push
2.Pop
3.Display
4.Exit
Enter your choice(1-4):2
Deleted element is 3
\** Stack Menu ****
1.Push
2.Pop
3.Display
4.Exit
Enter your choice(1-4):2
Stack is empty!!