summaryrefslogtreecommitdiffhomepage
path: root/c.html.markdown
diff options
context:
space:
mode:
authorLevi Bostian <levi.bostian@gmail.com>2015-10-12 23:14:27 -0500
committerLevi Bostian <levi.bostian@gmail.com>2015-10-12 23:14:27 -0500
commit841f4c3d4628e75e5d8f62adb285b4d6b8336fba (patch)
treec7c32eefadfcd29a23dbe925f90ebae0f7b15aff /c.html.markdown
parent3c45696a6223100e6831e640814fdbc13dc3fcb1 (diff)
parentc899b6605ef9667cb214c2163e7182ad41783be4 (diff)
Merge pull request #1399 from himanshu81494/master
example function added for call by reference
Diffstat (limited to 'c.html.markdown')
-rw-r--r--c.html.markdown44
1 files changed, 42 insertions, 2 deletions
diff --git a/c.html.markdown b/c.html.markdown
index 345dca7f..3339032f 100644
--- a/c.html.markdown
+++ b/c.html.markdown
@@ -6,6 +6,7 @@ contributors:
- ["Árpád Goretity", "http://twitter.com/H2CO3_iOS"]
- ["Jakub Trzebiatowski", "http://cbs.stgn.pl"]
- ["Marco Scannadinari", "https://marcoms.github.io"]
+ - ["himanshu", "https://github.com/himanshu81494"]
---
@@ -316,7 +317,29 @@ int main (int argc, char** argv)
exit(-1);
break;
}
-
+ /*
+ using "goto" in C
+ */
+ typedef enum { false, true } bool;
+ // for C don't have bool as data type :(
+ bool disaster = false;
+ int i, j;
+ for(i=0;i<100;++i)
+ for(j=0;j<100;++j)
+ {
+ if((i + j) >= 150)
+ disaster = true;
+ if(disaster)
+ goto error;
+ }
+ error :
+ printf("Error occured at i = %d & j = %d.\n", i, j);
+ /*
+ https://ideone.com/GuPhd6
+ this will print out "Error occured at i = 52 & j = 99."
+ */
+
+
///////////////////////////////////////
// Typecasting
///////////////////////////////////////
@@ -482,7 +505,24 @@ char c[] = "This is a test.";
str_reverse(c);
printf("%s\n", c); // => ".tset a si sihT"
*/
-
+/*
+as we can return only one variable
+to change values of more than one variables we use call by reference
+*/
+void swapTwoNumbers(int *a, int *b)
+{
+ int temp = *a;
+ *a = *b;
+ *b = temp;
+}
+/*
+int first = 10;
+int second = 20;
+printf("first: %d\nsecond: %d\n", first, second);
+swapTwoNumbers(&first, &second);
+printf("first: %d\nsecond: %d\n", first, second);
+// values will be swapped
+*/
// if referring to external variables outside function, must use extern keyword.
int i = 0;
void testFunc() {