Forum Replies Created
-
AuthorPosts
-
Humble
KeymasterThis reply has been marked as private.Humble
KeymasterThis reply has been marked as private.Humble
KeymasterThis reply has been marked as private.Humble
KeymasterThis reply has been marked as private.Humble
KeymasterThis reply has been marked as private.Humble
KeymasterThis reply has been marked as private.Humble
KeymasterIf you want to stash the untracked files try
git stash -uHumble
Keymaster#include
int main()
{
int *p = NULL;if (p == NULL)
{
printf (“p is NULL\n”);
}
else
{
printf (“p is not NULL\n”);}
}Above produce below result :
[hchiramm@humbles-lap ]$ ./a.out
p is NULLBut, if we have below code :
#include
int main()
{
int *p = NULL;
if (p)
{
printf (“p is NULL\n”);
}
else
{
printf (“p is not NULL\n”);}
}[hchiramm@humbles-lap ]$ ./a.out
p is not NULLBecause NULL is represented as binary zero in a system, that said, binary zero is treated as “false” in C, so else clause is getting executed..
In standard libike this:
#define NULL ((void*)0)
Dereferencing a NULL pointer will result in ‘segmentation fault” .
February 21, 2014 at 7:09 pm in reply to: How to list UUID, FSTYPE , LABEL of storage devices in a llinux system ? #2478Humble
KeymasterAlso you can use “blkid” command:
For ex:
[root@humbles-lap ]# blkid /dev/loop0: UUID="Yg52hp-YO2R-7QOr-11PV-fdC6-nqE1-Af0pS1" TYPE="LVM2_member" /dev/sda1: LABEL="WINRE_DRV" UUID="7870EA4270EA06AA" TYPE="ntfs" PARTLABEL="Basic data partition" PARTUUID="e5c49970-3e0d-4d76-b024-766f64258989" /dev/sda2: LABEL="SYSTEM_DRV" UUID="4EEC-B38E" TYPE="vfat" PARTLABEL="EFI system partition" PARTUUID="db3d31b3-05f9-4101-9bbf-1425fd68edb2" /dev/sda3: LABEL="LRS_ESP" UUID="0CED-2AB9" TYPE="vfat" PARTLABEL="Basic data partition" PARTUUID="a56b6cb2-e516-48f3-9adf-35cd11e76e54" /dev/sda4: PARTLABEL="Microsoft reserved partition" PARTUUID="7df2f17d-9751-4a77-828e-2bf7311c3a1f" /dev/sda5: LABEL="Windows8_OS" UUID="429CF07E9CF06E33" TYPE="ntfs" PARTLABEL="Basic data partition" PARTUUID="ad68292e-0517-4bff-b925-899dbe5ab015" /dev/sda6: LABEL="LENOVO" UUID="4228F2B328F2A4D7" TYPE="ntfs" PARTLABEL="Basic data partition" PARTUUID="495f8d21-0a95-4383-86cc-12f6c7d7bbeb" /dev/sda7: LABEL="PBR_DRV" UUID="F63AF44D3AF40BFD" TYPE="ntfs" PARTLABEL="Basic data partition" PARTUUID="368b12c6-c47f-4c1b-acfa-5bcf30f6e214" /dev/sda8: LABEL="/boot" UUID="3ba53f9b-f44b-4c3f-aaa2-0dfbbb75b1e5" TYPE="ext4" PARTUUID="ba3e3a96-a991-401b-a09e-730270d879eb" /dev/sda9: LABEL="/home" UUID="20ad6689-b5a3-4ec3-a9f4-e81d6360ca58" TYPE="ext4" PARTUUID="70ae19be-b309-4939-b236-039acc53718e" /dev/sda10: LABEL="/" UUID="6da5e19a-e9e8-4ad0-a04f-aeaca04035a2" TYPE="ext4" PARTUUID="44f32e05-158d-4535-a5db-40f1b0ded7ca" /dev/sda11: LABEL="swap" UUID="d080a09a-3b45-48d7-9410-ba3b07443388" TYPE="swap" PARTUUID="a61f716e-e187-4f7c-afb9-a44c28cb235f" /dev/sda12: PARTUUID="dc82d2c4-3f74-4b25-9f00-bfb340de03f4" For more information refer man page:
February 8, 2014 at 10:37 am in reply to: negative numbers, 2’s complement, signed/unsigned int/char .. #2358Humble
KeymasterIts always a doubt that whats default type for int and char . The default type for int is taken as signed.
How-ever char can be unsigned or signed .
/* Minimum and maximum values achar' can hold. */ # ifdef __CHAR_UNSIGNED__ # define CHAR_MIN 0 # define CHAR_MAX UCHAR_MAX # else # define CHAR_MIN SCHAR_MIN # define CHAR_MAX SCHAR_MAX # endif ` If you are with gcc compiler, the default is signed.. You can modify that with -funsigned-char option of gcc..
-funsigned-char Let the type "char" be unsigned, like "unsigned char". Each kind of machine has a default for what "char" should be. It is either like "unsigned char" by default or like "signed char" by default. Ideally, a portable program should always use "signed char" or "unsigned char" when it depends on the signedness of an object. But many programs have been written to use plain "char" and expect it to be signed, or expect it to be unsigned, depending on the machines they were written for. This option, and its inverse, let you make such a program work with the opposite default. The type "char" is always a distinct type from each of "signed char" or "unsigned char", even though its behavior is always just like one of those two. -fsigned-char Let the type "char" be signed, like "signed char". Note that this is equivalent to -fno-unsigned-char, which is the negative form of -funsigned-char. Likewise, the option -fno-signed-char is equivalent to -funsigned-char.
Humble
KeymasterThis reply has been marked as private.Humble
KeymasterThe order in which operators are evaluated is called operator precedence or the order of operations.
Unary operators ( ++ — + – ) order of evaluation is from right to left, so an expression like:
*p++;
would perform the ++ before the *
The comma operator (,) works almost like the semicolon ; that separates one C statement from another. The comma-separated expressions are evaluated from left to right.
Humble
KeymasterThis reply has been marked as private.Humble
KeymasterThis reply has been marked as private.Humble
KeymasterIf you are trying to convert the interger to string (opposite of what we discussed above) make use of sprintf() function as shown below:
$ cat str.c #include <stdio.h> #include <stdlib.h> int main() { char str[10]; sprintf (str,"%d", 123); puts(str); return 0; } it will return 123 as an output..January 13, 2014 at 6:46 am in reply to: Data structures in python continued.. (strings) .. [P-2] #2107Humble
KeymasterSome more slicing examples:
>>> str= "humble" >>> str[::-2] 'ebu' >>> str[::2] 'hml' >>> str[1:2] 'u' >>> str[1::] 'umble' >>> str[::3] 'hb' >>> str[:3] 'hum' >>>
Humble
Keymasterrepr() function can be used to convert an integer to a string..
>>> type(100) <type 'int'> >>> type(repr(100)) <type 'str'> >>> repr(100) '100' >>>
Humble
KeymasterAlso, if first arg (ie: func ) is “none”, the map() returns the elements of iteratable object as a tuple…
Humble
KeymasterIn python3 or above, the “return” of map() will be shown as an object: You need to input that to list to see the desired result..
Code:>>> l = [1,10,100]
>>> m = [2,20,200]
>>> map(lambda x,y: x*y, l,m)
<map object at 0x7f7753fcb790>
>>> list(map(lambda x,y: x*y, l,m))
[2, 200, 20000]
>>>Humble
KeymasterLambda functions are mainly used in combination with the functions filter(), map() and reduce().
Humble
KeymasterDo this :
>export PYTHONPATH=$PYTHONPATH:/path/to/subject/module
Humble
KeymasterSorry for being late here 🙂 ..
Please remember : ‘self’ have to be defined ‘explicitly’ in every method of a class.
The first argument of every class method, including __init__, is always a reference to the current instance of the class. By convention, this argument is always named self.
‘self’ is basically a temporary place holder for the object.As you know, the class can have __init__ method to start with. In the __init__ method, ‘self’ refers to the newly created object; in other class methods, it refers to the instance whose method was called. Because python works on ‘scopes’ and its bound to ‘objects’ or ‘instances’.
Although you need to specify ‘self’ explicitly when defining the method, you do not specify it when calling the method; Python will add it for you automatically.
Because of ‘self’ you have the capability of creating multiple objects from the same class.
I hope it helps .. Please let me know if you have any doubts.
Humble
KeymasterThe builtin python function called ‘reload’ can be used to reload a module inside the same program.
>>>> reload.__doc__ 'reload(module) -> module\n\nReload the module. The module must have been successfully imported before.' >>> For ex:
>>>> import os >>> os <module 'os' from '/usr/lib64/python2.7/os.pyc'> >>> reload(os) <module 'os' from '/usr/lib64/python2.7/os.pyc'> >>> os
-
AuthorPosts