Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pointer/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"markdown.validate.enabled": true
"markdown.validate.enabled": false
}
57 changes: 57 additions & 0 deletions pointer/setup/code-runners.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import { defineCodeRunnersSetup } from '@slidev/types'

export default defineCodeRunnersSetup(() => {
return {
async c(code) {
const JUDGE0_API = "http://localhost:2358/submissions?base64_encoded=true&wait=true"

// Matches "// input: {value}" anywhere in the line
const inputRegex = /\/\/\s*input:\s*([^\r\n]+)/gi
const matches = [...code.matchAll(inputRegex)]

// Join all found inputs with a newline for Judge0's stdin
const stdin = matches.map(m => m[1].trim()).join('\n')

const body = {
source_code: btoa(code),
language_id: 50,
stdin: btoa(stdin),
}

try {
const response = await fetch(JUDGE0_API, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify(body),
})

const result = await response.json()

// Decode results from Judge0 (Base64)
const output = result.stdout ? atob(result.stdout) : ''
const error = result.stderr ? atob(result.stderr) : ''
const compileErr = result.compile_output ? atob(result.compile_output) : ''

const text = output || error || compileErr || "Program executed (no output)."

return {
// Wrap in <pre> tag to ensure newlines are preserved
html: `<pre style="margin: 0; white-space: pre-wrap; word-wrap: break-word;" class="${
result.stdout ? 'text-green-400' : 'text-red-400'
}">${escapeHtml(text)}</pre>`,
}
} catch (e) {
return {
html: `<pre style="margin: 0; white-space: pre-wrap;" class="text-red-500 font-bold">Error connecting to Judge0: ${escapeHtml(e.message)}</pre>`,
}
}
},
}
})

// Helper function to escape HTML to prevent XSS
function escapeHtml(text: string): string {
const div = document.createElement('div')
div.textContent = text
return div.innerHTML
}
298 changes: 297 additions & 1 deletion pointer/slides.md
Original file line number Diff line number Diff line change
Expand Up @@ -307,13 +307,309 @@ int main(){
<!-- baki ja janar, pore janbi usage dekhle. -->

---
title: pointer to pointer
layout: section
---

# pointer to pointer

---
title: pointer to pointer visual
---

<v-switch>
<template #0>

```mermaid
flowchart RL

subgraph 1a[0x1003]
direction TB
1v[x = 5]
1t[int]

1v ~~~ 1t
end
```
</template>
<template #1>


```mermaid
flowchart LR

subgraph 1a[0x1003]
direction TB
1v[x = 5]
1t[int]

1v ~~~ 1t
end
style 1a stroke:#fab387, stroke-width:3px

subgraph 2a[0x1002]
direction TB
2v[p = 0x1003]
2t[int*]

2v ~~~ 2t
end

1a ~~~ 2a

2a p3@--> 1a

p3@{animate: true}
```

</template>
<template #2>

```mermaid
flowchart LR

subgraph 1a[0x1003]
direction TB
1v[x = 5]
1t[int]

1v ~~~ 1t
end
style 1a stroke:#fab387, stroke-width:3px

subgraph 2a[0x1002]
direction TB
2v[p = 0x1003]
2t[int*]

2v ~~~ 2t
end

subgraph 3a[0x1001]
direction TB
3v[q = 0x1002]
3t[int**]

3v ~~~ 3t
end

1a ~~~ 2a ~~~ 3a

3a p2@--> 2a p3@--> 1a

p2@{animate: true}
p3@{animate: true}
```

</template>
<template #3>

```mermaid
flowchart RL

subgraph 1a[0x1003]
direction TB
1v[x = 5]
1t[int]

1v ~~~ 1t
end
style 1a stroke:#fab387, stroke-width:3px

subgraph 2a[0x1002]
direction TB
2v[p = 0x1003]
2t[int*]

2v ~~~ 2t
end

subgraph 3a[0x1001]
direction TB
3v[q = 0x1002]
3t[int**]

3v ~~~ 3t
end

subgraph 4a[0x1004]
direction TB
4v[r = 0x1001]
4t[int***]:::hidden

4v ~~~ 4t
end

4a ~~~ 1a ~~~ 2a ~~~ 3a

3a p2@--> 2a p3@--> 1a

p2@{animate: true}
p3@{animate: true}
```
</template>
<template #4>

```mermaid
flowchart RL

subgraph 1a[0x1003]
direction TB
1v[x = 5]
1t[int]

1v ~~~ 1t
end
style 1a stroke:#fab387, stroke-width:3px

subgraph 2a[0x1002]
direction TB
2v[p = 0x1003]
2t[int*]

2v ~~~ 2t
end

subgraph 3a[0x1001]
direction TB
3v[q = 0x1002]
3t[int**]

3v ~~~ 3t
end

subgraph 4a[0x1004]
direction TB
4v[r = 0x1001]
4t[int***]

4v ~~~ 4t
end

4a ~~~ 1a ~~~ 2a ~~~ 3a

4a p1@--> 3a p2@--> 2a p3@--> 1a

p1@{animate: true}
p2@{animate: true}
p3@{animate: true}
```
</template>
</v-switch>

---
title: example pointer to pointer
---

```c {monaco-run}
#include<stdio.h>
int main(){
int x = 5;
int* p = &x; // adress of x -> p
*p = 6; // change value of address inside p to 5
int** q = &p; // address of p -> q
int*** r = &q; // adress of q -> r
}
```

<!--
1. *p.
2. *q
3. *(*q)
4. *(*r)
5. *(*(*r))

6. ***r = 10; print value of x
7. **q = *p + 2; x=?
-->


---
title: pointer as function argument
---

# pointer as function argument

- call by value
- call by reference

````md magic-move
```c
#include<stdio.h>
int increment(int a){
a = a + 1; // 11
}
int main(){
int a = 10;
increment(a); // 10
print("a = %d\n", a); // 10
}
```
```c
#include<stdio.h>
int increment(int a){
a = a + 1; // 11
return a;
}
int main(){
int a = 10;
increment(a); // 10
print("a = %d\n", a); // 10
}
```
```c
#include<stdio.h>
int increment(int a){
a = a + 1; // 11
return a;
}
int main(){
int a = 10;
a = increment(a); // 11
print("a = %d\n", a); // 11
}
```
```c
#include<stdio.h>
int increment(int a){
a = a + 1; // 11
}
int main(){
int a = 10;
increment(a); // 10
print("a = %d\n", a); // 10
}
```
```c
#include<stdio.h>
int increment(int a){
a = a + 1; // 11
}
int main(){
int a = 10;
increment(&a); // (0x1003)
print("a = %d\n", a); // 10
}
```
```c
#include<stdio.h>
int increment(int* a){
*a = *a + 1; // *(0x1003) + 1
}
int main(){
int a = 10;
increment(&a); // (0x1003)
print("a = %d\n", a); // 11
}
```
````

<!--
1. it copy the value, doent move the value.
2. if we wanted change, we have to return,
3. and assigned the returned value
3. we can pass the pointer. if we want direct.
-->

---
title: pointers and arrays
---
Expand Down