#include<stdio.h> #include<stdarg.h> void varfun(int n, ...); int main() { varfun(3, 7, -11, 0); return 0; } void varfun(int n, ...) { va_list ptr; int num; num = va_arg(ptr, int); printf("%d", num); }
#include<stdio.h> #include<stdarg.h> void display(int num, ...); int main() { display(4, 'A', 'a', 'b', 'c'); return 0; } void display(int num, ...) { char c; int j; va_list ptr; va_start(ptr, num); for(j=1; j<=num; j++) { c = va_arg(ptr, char); printf("%c", c); } }
#include<stdio.h> #include<stdarg.h> int main() { void display(char *s, int num1, int num2, ...); display("Hello", 4, 2, 12.5, 13.5, 14.5, 44.0); return 0; } void display(char *s, int num1, int num2, ...) { double c; char s; va_list ptr; va_start(ptr, s); c = va_arg(ptr, double); printf("%f", c); }
#include<stdio.h> #include<stdarg.h> int main() { void display(int num, ...); display(4, 12.5, 13.5, 14.5, 44.3); return 0; } void display(int num, ...) { float c; int j; va_list ptr; va_start(ptr, num); for(j=1; j<=num; j++) { c = va_arg(ptr, float); printf("%f", c); } }
#include<stdio.h> #include<stdarg.h> fun(...); int main() { fun(3, 7, -11.2, 0.66); return 0; } fun(...) { va_list ptr; int num; va_start(ptr, n); num = va_arg(ptr, int); printf("%d", num); }
#include<stdio.h> #define MAX 128 int main() { char mybuf[] = "India"; char yourbuf[] = "CURIOUSTAB"; char *const ptr = mybuf; *ptr = 'a'; ptr = yourbuf; return 0; }
Step 2: char yourbuf[] = "CURIOUSTAB"; The variable yourbuf is declared as an array of characters and initialized with string "CURIOUSTAB".
Step 3: char *const ptr = mybuf; Here, ptr is a constant pointer, which points at a char.
The value at which ptr it points is not a constant; it will not be an error to modify the pointed character; There will be an error only to modify the pointer itself.
Step 4: *ptr = 'a'; The value of ptr is assigned to 'a'.
Step 5: ptr = yourbuf; Here, we are changing the pointer itself, this will result in the error "cannot modify a const object".
#include<stdio.h> #include<stdarg.h> void display(char *s, ...); void show(char *t, ...); int main() { display("Hello", 4, 12, 13, 14, 44); return 0; } void display(char *s, ...) { show(s, ...); } void show(char *t, ...) { int a; va_list ptr; va_start(ptr, s); a = va_arg(ptr, int); printf("%f", a); }
#include<stdio.h> #include<stdarg.h> void varfun(int n, ...); int main() { varfun(3, 7, -11.2, 0.66); return 0; } void varfun(int n, ...) { float *ptr; int num; va_start(ptr, n); num = va_arg(ptr, int); printf("%d", num); }
Comments
There are no comments.Copyright ©CuriousTab. All rights reserved.