-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlec3.cpp
97 lines (79 loc) Β· 1.47 KB
/
lec3.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
// pointers with char array , function calls , length , palandrone string
#include<iostream>
using namespace std;
//function calls
void incr1(int num)
{
num++;
}
void incr2(int *num)
{
*num+=1;
}
void incr3(int &num)
{
num++;
}
// calculating length
int calcLen(const char *str)
{
int cnt=0 , i = 0;
while(str[cnt]!='\0')
{
cnt++;
i++;
}
return cnt;
}
//checking palindrome
bool isPln(const char *str)
{
int s= 0 , e = calcLen(str)-1;
while(s<=e)
{
if(str[s] == str[e])
{
s++ , e--;
}
else{
return false;
}
}
return true;
}
int main()
{
char ar[] = {'a' ,'b','c','d','e' };
// ,'\0'}; if needed
char *ptr = ar;
cout<<ptr<<endl;
cout<<ar<<endl;
cout<<*ptr<<endl;
// to print address
cout<<(void*)ptr<<endl;
cout<<(void*)ar<<endl;
//alternative
cout<<static_cast<void*>(ptr)<<endl;
// single char
char name = 'a';
cout<<name<<endl;
char *ptr1 = &name;
cout<<ptr1<<endl;
cout<<(void*)ptr1<<endl;
//call by value
int n = 10;
int temp = n;
cout<<n<<endl;
incr1(n);
cout<<n<<endl;
//call by pointer
incr2(&n);
cout<<n<<endl;
//call by refrence
incr3(n);
cout<<n<<endl;
const char str[] = "abcd";
cout<<calcLen(str)<<endl;
const char *paln1 = "ohod";
cout<<"Is \""<<paln1<<"\" a palindrone?"<<(isPln(paln1)?" Yes ":" No");
}