summaryrefslogtreecommitdiffhomepage
path: root/c.html.markdown
diff options
context:
space:
mode:
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() {