File tree Expand file tree Collapse file tree 3 files changed +32
-0
lines changed Expand file tree Collapse file tree 3 files changed +32
-0
lines changed Original file line number Diff line number Diff line change
1
+ #include < bits/stdc++.h>
2
+ using namespace std ;
3
+
4
+ int main (){
5
+ char str[10 ] = " abcd" ;
6
+ char *cptr = str; // same as char *cptr = &str[0], this works as str is char* type
7
+ cout << cptr << endl;
8
+ // char (*ch)[10] = &str; // char* ch = &str will give error as &str is char(*)[10] type
9
+ // cout << *ch << endl;
10
+ return 0 ;
11
+ }
Original file line number Diff line number Diff line change
1
+ #include < bits/stdc++.h>
2
+ using namespace std ;
3
+
4
+ int main ()
5
+ {
6
+ int *ptr = (int *)malloc (sizeof (int ));
7
+ free (ptr); // Now 'ptr' is a dangling pointer
8
+ *ptr = 10 ; // Accessing memory through a dangling pointer is undefined behavior
9
+ cout << *ptr << endl;
10
+ return 0 ;
11
+ }
Original file line number Diff line number Diff line change
1
+ #include < bits/stdc++.h>
2
+ using namespace std ;
3
+
4
+ int main ()
5
+ {
6
+ int *ptr; // 'ptr' is a wild pointer because it is uninitialized
7
+ *ptr = 10 ; // Accessing memory through a wild pointer is undefined behavior
8
+ cout << *ptr << endl; // doesn't print anything as the memory is not allocated
9
+ return 0 ;
10
+ }
You can’t perform that action at this time.
0 commit comments