klimi
it would try to save it to the address of ar which is undefined bahaviour, (and probably even worse)
tim
a=(int*)malloc(sizeof(int)*n); this looks weird
This, however, is completly fine
Anonymous
a=(int*)malloc(sizeof(int)*n); this looks weird
Will it multiply ' n ' with size of integer ?
klimi
This, however, is completly fine
oh right there is a scanf
klimi
also
klimi
why converting int to int*
klimi
the sizes are not always the same
klimi
alocate int* if you want to use it as int*
Anonymous
why converting int to int*
Because malloc returns void* so in order to use it according to your need you'll have to typecast
klimi
(also C will do this conversion implicitly)
klimi
oh i dont know anything about c++
klimi
i know just c
tim
same, I just pick up some bits of C++ here and there
Anonymous
i know just c
I was talking about c too... I know only c
Anonymous
i know just c
What was your doubt klimi ?
klimi
What was your doubt klimi ?
i didn't have any
Bharti
Hey guys... Tmrw is my mid term for c++ ...Wht topics should I prepare ?🥺
Rohan
Therefore I wrote*ar and it didn't gave any compilation error but didn't run...which is even more confusing
Rohan
Any suggestions or explanation about this?
Anonymous
Anonymous
Does anyone have c++ basic project using oop
Hugo
/get cbook
Terrence
Thanks Rose.. I am ready to code with you guys
Terrence
oh i dont know anything about c++
C++ isn't hard.. It involves dealing with classes and objects
Terrence
C++ isn't hard.. It involves dealing with classes and objects
It's a matter of mastering the concept of how to use the classes in classifying the objects involved and allocating values for the objects in the main function
Rohan
Show us your code
#include<stdio.h> #include<conio.h> #include<stdlib.h> int main() { int *a; int ar; int i,n; printf("How many"); scanf("%d",&n); a=(int*)malloc(sizeof(int)*n); *ar=(int*)malloc(sizeof(int)*n); printf("Enter %d numbers\n",n); for(i=0;i<n;i++) { scanf("%d",(a+i)); *(ar+i)=(a+i);//storing the address } printf("Traversing using pointer variable"); for(i=0;i<n;i++) { printf("Address of a[%d] is %d and value is %d\n",i,*(ar+i),(ar+i)); } printf("\n"); printf("Traversing using original array"); for(i=0;i<n;i++) { printf("Address of a[%d] is %d and value is %d\n",i,a+i,*(a+i)); } return 0; }
Ssssss
how to add #include"Data_base.h" in vscode? please help
olli
how to add #include"Data_base.h" in vscode? please help
most compilers try to lookup Data_base.h in the same directory it is included from, there should be nothing special about vscode. So you can just place the file next to the source file it is included from.
Rohan
You wrote int *a; Int ar; And below in scanf you used *ar a Is it right? You're using normal int variable as pointer???
#include<stdio.h> #include<conio.h> #include<stdlib.h> int main() { int *a; int ar; int i,n; printf("How many"); scanf("%d",&n); a=(int*)malloc(sizeof(int)*n); ar=(int)malloc(sizeof(int*)*n); printf("Enter %d numbers\n",n); for(i=0;i<n;i++) { scanf("%d",(a+i)); *(ar+i)=(a+i);//storing the address } printf("\nTraversing using pointer variable\n"); for(i=0;i<n;i++) { printf("Address of a[%d] is %d and value is %d\n",i,*(ar+i),**(ar+i)); } printf("\nTraversing using original array\n"); for(i=0;i<n;i++) { printf("Address of a[%d] is %d and value is %d\n",i,a+i,*(a+i)); } return 0; }
olli
I didn't understand
your code says int ar; because using ** outside of backticks is interpreted as "styled text" https://core.telegram.org/api/entities
Rohan
#include<stdio.h> #include<conio.h> #include<stdlib.h> int main() { int *a; int ar; int i,n; printf("How many"); scanf("%d",&n); a=(int*)malloc(sizeof(int)*n); ar=(int)malloc(sizeof(int*)*n); printf("Enter %d numbers\n",n); for(i=0;i<n;i++) { scanf("%d",(a+i)); *(ar+i)=(a+i);//storing the address } printf("\nTraversing using pointer variable\n"); for(i=0;i<n;i++) { printf("Address of a[%d] is %d and value is %d\n",i,*(ar+i),**(ar+i)); } printf("\nTraversing using original array\n"); for(i=0;i<n;i++) { printf("Address of a[%d] is %d and value is %d\n",i,a+i,*(a+i)); } return 0; }
Rohan
#include<stdio.h> #include<conio.h> #include<stdlib.h> int main() { int *a; int ar; int i,n; printf("How many"); scanf("%d",&n); a=(int*)malloc(sizeof(int)*n); ar=(int)malloc(sizeof(int*)*n); printf("Enter %d numbers\n",n); for(i=0;i<n;i++) { scanf("%d",(a+i)); *(ar+i)=(a+i);//storing the address } printf("\nTraversing using pointer variable\n"); for(i=0;i<n;i++) { printf("Address of a[%d] is %d and value is %d\n",i,*(ar+i),**(ar+i)); } printf("\nTraversing using original array\n"); for(i=0;i<n;i++) { printf("Address of a[%d] is %d and value is %d\n",i,a+i,*(a+i)); } return 0; }
olli
Still **ar is not showing
yes, because this is not markdown. If you use markdown it shows as #include<stdio.h> #include<stdlib.h> int main() { int *a; int **ar; int i,n; ...
Rohan
Ok, I will learn about it
AKILA
I installed linux mint few minutes ago and tried c hello world gcc main.c -o main amd it says #include <stdio.h> is not such a file or directory
Anonymous
Can someone tell me how to make seprate class files in cpp
Anonymous
Please
Talula
C++ isn't hard.. It involves dealing with classes and objects
C++ isn't hard it is actually easier than C...
MᏫᎻᎯᎷᎷᎬᎠ
C++ isn't hard it is actually easier than C...
If in terms of learning, it's super harder than C
Talula
If in terms of learning, it's super harder than C
Yeah but as a programming language I would prefer C++ over C every time and for everything, specially if I have to work with strings.
Anonymous
Bruuuv
C++ template metaprogramming is another beast, great if you know how to use but hard to learn
MᏫᎻᎯᎷᎷᎬᎠ
Concepts added a lot more stuff and simplified some things
Stay Forward
/getcbook
𝗕𝗔𝗛𝗔𝗥‌
hi every one lam need person study IT?
Anonymous
#include <stdio.h> int main() { int n, i; unsigned long long fact = 1; printf("Enter an integer: "); scanf("%d", &n); for (i = 1; i <= n; ++i) { fact *= i; } printf("Factorial of %d = %llu", n, fact); return 0; } %llu means????
Anonymous
what else i can use instead of llu?
Terrence
Anonymous
what else i can use instead of llu?
Search for format specifier in cppreference. You will get the full list.. %llu would be apt for a program that calculates factorials because they can grow very large
Anonymous
what else i can use instead of llu?
Here are some commonly used conversion specifiers (not a comprehensive list): %d int (signed decimal integer) %u unsigned decimal integer %f floating point values (fixed notation) - float, double %e floating point values (exponential notation) %s string %c character
Anonymous
%i or %u for unsigned integer, %lli or %lld for signed long long, %lu for unsigned long, %hi for signed short and %hu for unsigned short
Anonymous
#include <stdio.h> int main() { int n, i; unsigned long long fact = 1; printf("Enter an integer: "); scanf("%d", &n); for (i = 1; i <= n; ++i) { fact *= i; } printf("Factorial of %d = %llu", n, fact); return 0; } %llu means????
%d, %f, %c etc...... Are called format specifier... It says what is the format in which you want to see the output. Ex:- " %d "means we want the bit to be interpreted as decimal no.
Anonymous
Format SpecifierType:------- %cCharacter %dSigned integer %e or %EScientific notation of floats %fFloat values %g or %GSimilar as %e or %E%hiSigned integer (short)%hu Unsigned Integer (short)%iUnsigned integer %l or %ld or %liLong %lf Double %Lf Long double %lu Unsigned int or unsigned long %lli or %lldLong long %llu Unsigned long long %o Octal representation %p Pointer %sString%uUnsigned int%x or %XHexadecimal representation%n
B S
Please teach me c++ I want to become coder
Anonymous
Please teach me c++ I want to become coder
no, you're already old for that
B S
no, you're already old for that
Age doesn't matter for learning
Anonymous
Age doesn't matter for learning
in your case, there's an exception
Anonymous
It's only need willingness to learn ,practice ...
Hanz
/report offtopic