What's the difference between %x and %p ? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

What's the difference between %x and %p ?

In C, pointer's value is the address of the variable that is pointing to. To display that address I used %p and %x and I found similarities in the last 8 digits but the first four digits after the ( 0×) are not in %x display, so what do those digits refer to ? https://code.sololearn.com/cLJ5ckUhcGuw/?ref=app

5th Sep 2023, 6:41 AM
الحسين محمد عبدالله
الحسين محمد عبدالله - avatar
2 Answers
0
you are using <%x>, which expects <unsigned int> whereas <&j> is of type <int *>. format specifier mismatch in printf leads to undefined behaviour. C Standard: 7.19.6.1: para 9: " If a conversion specification is invalid, the behavior is undefined.225) If any argument is not the correct type for the corresponding coversion specification, the behavior is undefined. "
5th Sep 2023, 4:39 PM
MO ELomari
0
MO ELomari طيب اوصف لك سؤالي بالعربي يمكن فهمتك أو فهمتني غلط ال address الخاص بالمساحة التخزينية المحجوزة عبارة عن ٨ خانات مثلاً (11b51064) و هذا في حالة استخدام %x لكن عند استخدامي ل %p زي ما متوضح في الكود اظهرلي كل مرة تطابق في اخر ٨ خانات و هما ال address فعلاً لكن في زيادة (0×7fff11b51064) بالنسبة لل 7 و ال ff اللي بعدها كل مرة اشغل البرنامج تظل ثابتة لكن الخانة الرابعة متغيرة ده كده بيشير لايه لاني قرأت تعليقات إن الأصح استخداما مع ال pointers هو %p لانه مش بيعمل segmentation فأكيد الزيادة ديه لها معني و دلالة و شكراً لك أخي
5th Sep 2023, 9:25 PM
الحسين محمد عبدالله
الحسين محمد عبدالله - avatar